aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Martindale <awiamartindale@googlemail.com>2011-09-07 11:31:02 +0100
committerAdam Martindale <awiamartindale@googlemail.com>2011-09-07 11:31:02 +0100
commitcd0fdd04f3108f61482919309b2a2da5c33f6872 (patch)
tree99710b299a02fa58382df101766892c0c3b679a7
parentdc16d95ed5a4b5f15f327cbe609414dc9e5d6225 (diff)
parentba3448fb8093afd9d298cef1123a1bedfea13999 (diff)
downloadpunchingbag-cd0fdd04f3108f61482919309b2a2da5c33f6872.tar
punchingbag-cd0fdd04f3108f61482919309b2a2da5c33f6872.tar.gz
Merge branch 'master' of gitorious.org:punchingbag/punchingbag
-rwxr-xr-xArduino/ButtonMatrix/ButtonMatrix.pde28
-rw-r--r--Arduino/LEDMatrix/LEDMatrix.pde34
-rwxr-xr-xArduino/Libraies/AS1107/AS1107.h6
-rw-r--r--PunchingBag/.settings/org.eclipse.jdt.core.prefs8
-rw-r--r--PunchingBag/src/AccelListener.java7
-rw-r--r--PunchingBag/src/Arduino.java42
-rw-r--r--PunchingBag/src/Font.java374
-rw-r--r--PunchingBag/src/PunchingBag.java21
-rw-r--r--PunchingBag/src/PunchingBagGUI.java4
9 files changed, 501 insertions, 23 deletions
diff --git a/Arduino/ButtonMatrix/ButtonMatrix.pde b/Arduino/ButtonMatrix/ButtonMatrix.pde
index 6ce18f4..1ed494c 100755
--- a/Arduino/ButtonMatrix/ButtonMatrix.pde
+++ b/Arduino/ButtonMatrix/ButtonMatrix.pde
@@ -3,6 +3,14 @@
const byte ROWS = 19;
const byte COLS = 8;
+
+// these constants describe the pins for the acellarometer . They won't change:
+const int groundpin = 18; // analog input pin 4 -- ground
+const int powerpin = 19; // analog input pin 5 -- voltage
+const int xpin = A3; // x-axis of the accelerometer
+const int ypin = A2; // y-axis
+const int zpin = A1; // z-axis (only on 3-axis models)
+
/* Each of the buttons can be refered to by a number
At the moment the byte overflow for the 127+ numbers is dealt with at the
getKey time, but if a unsigned byte could be used here it would remove the need
@@ -33,6 +41,14 @@ void setup(){
Serial.begin(115200);
Serial.println("Go");
+ // Provide ground and power by using the analog inputs as normal
+ // digital pins. This makes it possible to directly connect the
+ // breakout board to the Arduino. If you use the normal 5V and
+ // GND pins on the Arduino, you can remove these lines.
+ pinMode(groundpin, OUTPUT);
+ pinMode(powerpin, OUTPUT);
+ digitalWrite(groundpin, LOW);
+ digitalWrite(powerpin, HIGH);
}
/* Send numbers back and forth to test the integrity of the serial communication
Computer sends the first byte
@@ -58,4 +74,16 @@ void loop(){
if (customKey != NO_KEY){
Serial.println(customKeyInt);
}
+
+ // print the sensor values:
+ Serial.print(analogRead(xpin));
+ // print a tab between values:
+ Serial.print("\t");
+ Serial.print(analogRead(ypin));
+ // print a tab between values:
+ Serial.print("\t");
+ Serial.print(analogRead(zpin));
+ Serial.println();
+ // delay before next reading:
+ delay(100);
}
diff --git a/Arduino/LEDMatrix/LEDMatrix.pde b/Arduino/LEDMatrix/LEDMatrix.pde
new file mode 100644
index 0000000..0d3994b
--- /dev/null
+++ b/Arduino/LEDMatrix/LEDMatrix.pde
@@ -0,0 +1,34 @@
+// test program for three cascaded AS1107
+// if you got a different configuration you need to
+// modify the library itself.
+
+#include <AS1107.h>
+
+// Arduino pins
+const byte CsnPin = 2 ; // Chip select (Low active)
+const byte ClkPin = 3 ; // Serial Clockq
+const byte DataPin = 4 ; // Serial Data
+
+byte buffer [ 8 ] ; // Screen buffer (No. of modules * 8)
+AS1107 matrix ( CsnPin, ClkPin, DataPin ) ;
+
+const byte d = 0 ;
+int count= 1 ;
+void setup ( )
+{
+ matrix. Init ( buffer, 7, 7, 0 ) ;
+}
+
+void loop ( )
+{
+ for (int x=0; x<8; x++) {
+ for (int y=0; y<8; y++) {
+ matrix.SetLed(x,y,1);
+ matrix.Update();
+ delay(1000);
+ matrix.SetLed(x,y,0);
+ matrix.Update();
+ delay(1000);
+ }
+ }
+}
diff --git a/Arduino/Libraies/AS1107/AS1107.h b/Arduino/Libraies/AS1107/AS1107.h
index 60ad6ad..80b01da 100755
--- a/Arduino/Libraies/AS1107/AS1107.h
+++ b/Arduino/Libraies/AS1107/AS1107.h
@@ -59,9 +59,9 @@ class AS1107
// ***************************************
// Set your module configuration here
// ***************************************
- static const byte Maxx=15; // maximum x - Pixels of the Module
- static const byte Maxy=7; // maximum y - Pixels of the Module
- static const byte HighestCtrlNum=1; // Number of Matrix modules -1 (0 = single module)
+ static const byte Maxx=8; // maximum x - Pixels of the Module
+ static const byte Maxy=19; // maximum y - Pixels of the Module
+ static const byte HighestCtrlNum=5; // Number of Matrix modules -1 (0 = single module)
private:
byte _cspin;
diff --git a/PunchingBag/.settings/org.eclipse.jdt.core.prefs b/PunchingBag/.settings/org.eclipse.jdt.core.prefs
index 9fd8280..394e4df 100644
--- a/PunchingBag/.settings/org.eclipse.jdt.core.prefs
+++ b/PunchingBag/.settings/org.eclipse.jdt.core.prefs
@@ -1,12 +1,12 @@
-#Wed Jul 13 14:12:05 BST 2011
+#Tue Sep 06 14:26:41 BST 2011
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
-org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
-org.eclipse.jdt.core.compiler.source=1.6
+org.eclipse.jdt.core.compiler.source=1.7
diff --git a/PunchingBag/src/AccelListener.java b/PunchingBag/src/AccelListener.java
new file mode 100644
index 0000000..a3ad465
--- /dev/null
+++ b/PunchingBag/src/AccelListener.java
@@ -0,0 +1,7 @@
+import java.util.EventListener;
+
+interface AccelListener extends EventListener {
+
+ void AccelChanged();
+
+}
diff --git a/PunchingBag/src/Arduino.java b/PunchingBag/src/Arduino.java
index 5e6e288..f76bcf6 100644
--- a/PunchingBag/src/Arduino.java
+++ b/PunchingBag/src/Arduino.java
@@ -11,7 +11,10 @@ import java.io.OutputStream;
import gnu.io.*;
-public class Arduino {
+public class Arduino implements Runnable {
+
+ InputStream in;
+ OutputStream out;
static void listPorts()
{
@@ -85,12 +88,10 @@ public class Arduino {
SerialPort serialPort = (SerialPort) commPort;
serialPort.setSerialPortParams(57600,SerialPort.DATABITS_8,SerialPort.STOPBITS_1,SerialPort.PARITY_NONE);
- InputStream in = serialPort.getInputStream();
- OutputStream out = serialPort.getOutputStream();
+ in = serialPort.getInputStream();
+ out = serialPort.getOutputStream();
- (new Thread(new SerialReader(in))).start();
- (new Thread(new SerialWriter(out))).start();
-
+ (new Thread(this)).start();
}
else
{
@@ -100,7 +101,7 @@ public class Arduino {
}
/** */
- public static class SerialReader implements Runnable
+ public class SerialReader implements Runnable
{
InputStream in;
@@ -118,6 +119,7 @@ public class Arduino {
while ( ( len = this.in.read(buffer)) > -1 )
{
System.out.print(new String(buffer,0,len));
+ input(new String(buffer,0,len));
}
}
catch ( IOException e )
@@ -126,9 +128,13 @@ public class Arduino {
}
}
}
+
+ public static void input(String string) {
+
+ }
/** */
- public static class SerialWriter implements Runnable
+ public class SerialWriter implements Runnable
{
OutputStream out;
@@ -154,4 +160,24 @@ public class Arduino {
}
}
+ public void run() {
+ byte[] buffer = new byte[1024];
+ int len = -1;
+ try
+ {
+ while ( ( len = this.in.read(buffer)) > -1 )
+ {
+ System.out.print(new String(buffer,0,len));
+ input(new String(buffer,0,len));
+ }
+ }
+ catch ( IOException e )
+ {
+ e.printStackTrace();
+ }
+
+ }
+
+
+
}
diff --git a/PunchingBag/src/Font.java b/PunchingBag/src/Font.java
new file mode 100644
index 0000000..a8996bf
--- /dev/null
+++ b/PunchingBag/src/Font.java
@@ -0,0 +1,374 @@
+
+public class Font {
+ char font[] = {
+ // -------- Space
+ 0b00000000,
+ 0b00000000,
+ 0b00000000,
+ 0b00000000,
+ // -------- A
+ 0b01111110,
+ 0b10010000,
+ 0b10010000,
+ 0b01111110,
+ // -------- B
+ 0b01101100,
+ 0b10010010,
+ 0b10010010,
+ 0b11111110,
+ // -------- C
+ 0b10000010,
+ 0b10000010,
+ 0b01111100,
+ // -------- D
+ 0b00111000,
+ 0b01000100,
+ 0b10000010,
+ 0b11111110,
+ // -------- E
+ 0b10000010,
+ 0b10010010,
+ 0b11111110,
+ // -------- F
+ 0b10000000,
+ 0b10010000,
+ 0b11111110,
+ // -------- G
+ 0b01011100,
+ 0b10010010,
+ 0b10000010,
+ 0b01111100,
+ // -------- H
+ 0b11111110,
+ 0b00010000,
+ 0b00010000,
+ 0b11111110,
+ // -------- I
+ 0b10000010,
+ 0b11111110,
+ 0b10000010,
+ // -------- J
+ 0b11111100,
+ 0b00000010,
+ 0b00001100,
+ // -------- K
+ 0b10000110,
+ 0b01001000,
+ 0b00110000,
+ 0b11111110,
+ // -------- L
+ 0b00000010,
+ 0b00000010,
+ 0b11111110,
+ // -------- M
+ 0b11111110,
+ 0b01100000,
+ 0b00111100,
+ 0b01100000,
+ 0b11111110,
+ // -------- N
+ 0b11111110,
+ 0b00011000,
+ 0b01100000,
+ 0b11111110,
+ // -------- O
+ 0b01111100,
+ 0b10000010,
+ 0b10000010,
+ 0b01111100,
+ // -------- P
+ 0b01100000,
+ 0b10010000,
+ 0b10010000,
+ 0b11111110,
+ // -------- Q
+ 0b01111010,
+ 0b10000100,
+ 0b10001010,
+ 0b01111100,
+ // -------- R
+ 0b01100110,
+ 0b10011000,
+ 0b10010000,
+ 0b11111110,
+ // -------- S
+ 0b10001100,
+ 0b10010010,
+ 0b01100010,
+ // -------- T
+ 0b10000000,
+ 0b11111110,
+ 0b10000000,
+ // -------- U
+ 0b11111100,
+ 0b00000010,
+ 0b00000010,
+ 0b11111100,
+ // -------- V
+ 0b11000000,
+ 0b00111000,
+ 0b00000110,
+ 0b00111000,
+ 0b11000000,
+ // -------- W
+ 0b11111110,
+ 0b00001100,
+ 0b00111000,
+ 0b00001100,
+ 0b11111110,
+ // -------- X
+ 0b11000110,
+ 0b00111000,
+ 0b00111000,
+ 0b11000110,
+ // -------- Y
+ 0b11100000,
+ 0b00011110,
+ 0b11100000,
+ // -------- Z
+ 0b11000010,
+ 0b10110010,
+ 0b10001110,
+ // -------- Unknown character
+ 0b00111000,
+ 0b00111000,
+ 0b00111000,
+ // -------- 0
+ 0b01111100,
+ 0b10100010,
+ 0b10010010,
+ 0b01111100,
+ // -------- 1
+ 0b11111110,
+ 0b01000000,
+ // -------- 2
+ 0b01100010,
+ 0b10010010,
+ 0b10001110,
+ // -------- 3
+ 0b01101100,
+ 0b10010010,
+ 0b10000010,
+ // -------- 4
+ 0b11111110,
+ 0b00010000,
+ 0b11110000,
+ // -------- 5
+ 0b10001100,
+ 0b10010010,
+ 0b11110010,
+ // -------- 6
+ 0b01001100,
+ 0b10010010,
+ 0b10010010,
+ 0b01111100,
+ // -------- 7
+ 0b11100000,
+ 0b10011110,
+ 0b10000000,
+ // -------- 8
+ 0b01101100,
+ 0b10010010,
+ 0b10010010,
+ 0b01101100,
+ // -------- 9
+ 0b01111100,
+ 0b10010010,
+ 0b10010010,
+ 0b01100100,
+ // -------- :
+ 0b00100100,
+ // -------- ;
+ 0b00100110,
+ 0b00000001,
+ // -------- !
+ 0b01100000,
+ 0b11111010,
+ 0b01100000,
+ // -------- Heart
+ 0b01111000,
+ 0b11111100,
+ 0b11111110,
+ 0b01111111,
+ 0b11111110,
+ 0b11111100,
+ 0b01111000,
+ // -------- <
+ 0b01000100,
+ 0b00101000,
+ 0b00010000,
+ // -------- =
+ 0b00101000,
+ 0b00101000,
+ 0b00101000,
+ 0b00101000,
+ // -------- >
+ 0b00010000,
+ 0b00101000,
+ 0b01000100,
+ // -------- ?
+ 0b01100000,
+ 0b10011010,
+ 0b10000000,
+ // -------- @
+ 0b01111100,
+ 0b10000010,
+ 0b10111010,
+ 0b10100010,
+ 0b01011100,
+ // -------- (
+ 0b10000010,
+ 0b01111100,
+ // -------- )
+ 0b01111100,
+ 0b10000010,
+ // -------- *
+ 0b00101000,
+ 0b00010000,
+ 0b00101000,
+ // -------- +
+ 0b00010000,
+ 0b00010000,
+ 0b01111100,
+ 0b00010000,
+ 0b00010000,
+ // -------- ,
+ 0b00000110,
+ 0b00000001,
+ // -------- -
+ 0b00010000,
+ 0b00010000,
+ 0b00010000,
+ 0b00010000,
+ // -------- .
+ 0b00000010,
+ // -------- /
+ 0b11000000,
+ 0b00111000,
+ 0b00000110,
+ // -------- a
+ 0b00111110,
+ 0b00100010,
+ 0b00100010,
+ 0b00011100,
+ // -------- b
+ 0b00011100,
+ 0b00100010,
+ 0b00100010,
+ 0b11111110,
+ // -------- c
+ 0b00100010,
+ 0b00100010,
+ 0b00011100,
+ // -------- d
+ 0b11111110,
+ 0b00100010,
+ 0b00100010,
+ 0b00011100,
+ // -------- e
+ 0b00011000,
+ 0b00101010,
+ 0b00101010,
+ 0b00011100,
+ // -------- f
+ 0b10010000,
+ 0b01111110,
+ 0b00010000,
+ // -------- g
+ 0b00111110,
+ 0b00100101,
+ 0b00100101,
+ 0b00011000,
+ // -------- h
+ 0b00011110,
+ 0b00100000,
+ 0b00100000,
+ 0b11111110,
+ // -------- i
+ 0b00000010,
+ 0b01011110,
+ 0b00010010,
+ // -------- j
+ 0b01011110,
+ 0b00000001,
+ 0b00000001,
+ // -------- k
+ 0b00100010,
+ 0b00010100,
+ 0b00001000,
+ 0b11111110,
+ // -------- l
+ 0b00000010,
+ 0b11111100,
+ // -------- m
+ 0b00011110,
+ 0b00100000,
+ 0b00111110,
+ 0b00100000,
+ 0b00111110,
+ // -------- n
+ 0b00011110,
+ 0b00100000,
+ 0b00100000,
+ 0b00111110,
+ // -------- o
+ 0b00011100,
+ 0b00100010,
+ 0b00100010,
+ 0b00011100,
+ // -------- p
+ 0b00011100,
+ 0b00100010,
+ 0b00100010,
+ 0b00111111,
+ // -------- q
+ 0b00111111,
+ 0b00100010,
+ 0b00100010,
+ 0b00011100,
+ // -------- r
+ 0b00010000,
+ 0b00100000,
+ 0b00111110,
+ // -------- s
+ 0b00100100,
+ 0b00101010,
+ 0b00101010,
+ 0b00010010,
+ // -------- t
+ 0b00100010,
+ 0b11111100,
+ 0b00100000,
+ // -------- u
+ 0b00111110,
+ 0b00000010,
+ 0b00000010,
+ 0b00111100,
+ // -------- v
+ 0b00111000,
+ 0b00000110,
+ 0b00111000,
+ // -------- w
+ 0b00111110,
+ 0b00000010,
+ 0b00011110,
+ 0b00000010,
+ 0b00111100,
+ // -------- x
+ 0b00110110,
+ 0b00001000,
+ 0b00110110,
+ // -------- y
+ 0b00111110,
+ 0b00000101,
+ 0b00000101,
+ 0b00111001,
+ // -------- z
+ 0b00110010,
+ 0b00101010,
+ 0b00100110,
+ 0b00100010,
+ 0b11000001
+ };
+
+}
diff --git a/PunchingBag/src/PunchingBag.java b/PunchingBag/src/PunchingBag.java
index d6eca55..bcaf220 100644
--- a/PunchingBag/src/PunchingBag.java
+++ b/PunchingBag/src/PunchingBag.java
@@ -20,6 +20,8 @@ public class PunchingBag implements Runnable {
boolean buttonsChanged = false;
private ArrayList<Effect> runningEffects = new ArrayList<Effect>();
+
+ ButtonArduino buttonArduino = new ButtonArduino();
public enum Colour {
None, Red, Yellow, Green
@@ -32,6 +34,8 @@ public class PunchingBag implements Runnable {
// Is there a better class for this? One that it is not a swing class.
private EventListenerList buttonListenerList = new EventListenerList();
private EventListenerList ledListenerList = new EventListenerList();
+ private EventListenerList accelListenerList = new EventListenerList();
+
public PunchingBag() {
new Thread(this).start();
@@ -50,6 +54,10 @@ public class PunchingBag implements Runnable {
public void addLEDChangeListener(LEDListener l) {
ledListenerList.add(LEDListener.class, l);
}
+
+ public void addLEDChangeListener(AccelListener l) {
+ accelListenerList.add(AccelListener.class, l);
+ }
public Colour getLED(int x, int y) {
return leds[x][y];
@@ -75,7 +83,8 @@ public class PunchingBag implements Runnable {
abstract class Effect {
long lastRefresh = 0;
boolean stop = false;
- int refreshRate = 60; // Times per second to refresh
+
+ // int refreshRate = 60; // Times per second to refresh
public void stop() {
stop = true;
@@ -254,16 +263,16 @@ public class PunchingBag implements Runnable {
public void run() {
while (true) {
synchronized (runningEffects) { // Should prevent
- // ConcurrentModificationException's
- // (havent managed to produce one
- // though
+ // ConcurrentModificationException's
+ // (havent managed to produce one
+ // though
for (Iterator<Effect> iter = runningEffects.iterator(); iter
.hasNext();) {
Effect ef = (Effect) iter.next();
if (ef.stop) {
iter.remove();
- } else if ((ef.lastRefresh + (1000 / ef.refreshRate)) <= System
- .currentTimeMillis()) {
+ } else {// if ((ef.lastRefresh + (1000 / ef.refreshRate)) <=
+ // Systems.currentTimeMillis()) {
ef.draw();
ef.lastRefresh = System.currentTimeMillis();
}
diff --git a/PunchingBag/src/PunchingBagGUI.java b/PunchingBag/src/PunchingBagGUI.java
index 1db9d68..63f05ae 100644
--- a/PunchingBag/src/PunchingBagGUI.java
+++ b/PunchingBag/src/PunchingBagGUI.java
@@ -21,12 +21,12 @@ public class PunchingBagGUI implements MouseListener, MouseMotionListener,
static JFrame frame;
static JFrame bagSimFrame;
- static PunchingBag bag = new PunchingBag();
-
// Contact
public enum Direction {
None, Up, Down, Left, Right
};
+
+ PunchingBag bag = new PunchingBag();
final boolean useDebugScreen = true;