aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Baines <cbaines8@gmail.com>2011-09-07 16:38:19 +0100
committerChristopher Baines <cbaines8@gmail.com>2011-09-07 16:38:19 +0100
commita09647f50841e23e4783ef8c34faa9219054234f (patch)
tree98b9b2285cbc63e12a0bdeea0ef5e2bbe23d8f99
parent89557022d57e3d72ea9021691d70c80763fa31b6 (diff)
downloadpunchingbag-a09647f50841e23e4783ef8c34faa9219054234f.tar
punchingbag-a09647f50841e23e4783ef8c34faa9219054234f.tar.gz
More arduino stuff.
-rwxr-xr-xArduino/ButtonMatrix/ButtonMatrix.pde14
-rw-r--r--PunchingBag/src/Arduino.java11
-rw-r--r--PunchingBag/src/PunchingBag.java29
3 files changed, 46 insertions, 8 deletions
diff --git a/Arduino/ButtonMatrix/ButtonMatrix.pde b/Arduino/ButtonMatrix/ButtonMatrix.pde
index 1ed494c..41ae6ab 100755
--- a/Arduino/ButtonMatrix/ButtonMatrix.pde
+++ b/Arduino/ButtonMatrix/ButtonMatrix.pde
@@ -1,8 +1,7 @@
- #include <Keypad.h> // Needs to be the modified version
+#include <Keypad.h> // Needs to be the modified version
const byte ROWS = 19;
-const byte COLS = 8;
-
+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
@@ -10,6 +9,7 @@ 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)
+const int selfTest = A0;
/* 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
@@ -38,7 +38,7 @@ byte rowPins[ROWS] = {14, 15, 16, 17, 18, 19, 20, 21, 22, 24, 26, 28, 30, 32, 34
Keypad keypad = Keypad( makeKeymap(keys), colPins, rowPins, COLS, ROWS);
void setup(){
- Serial.begin(115200);
+ Serial.begin(9600);
Serial.println("Go");
// Provide ground and power by using the analog inputs as normal
@@ -47,8 +47,10 @@ void setup(){
// GND pins on the Arduino, you can remove these lines.
pinMode(groundpin, OUTPUT);
pinMode(powerpin, OUTPUT);
+ //pinMode(selfTest, OUTPUT);
digitalWrite(groundpin, LOW);
digitalWrite(powerpin, HIGH);
+ //digitalWrite(selfTest, HIGH);
}
/* Send numbers back and forth to test the integrity of the serial communication
Computer sends the first byte
@@ -80,10 +82,10 @@ void loop(){
// print a tab between values:
Serial.print("\t");
Serial.print(analogRead(ypin));
- // print a tab between values:
+ // print a tab between values:
Serial.print("\t");
Serial.print(analogRead(zpin));
Serial.println();
// delay before next reading:
- delay(100);
+ delay(10);
}
diff --git a/PunchingBag/src/Arduino.java b/PunchingBag/src/Arduino.java
index f76bcf6..12df25f 100644
--- a/PunchingBag/src/Arduino.java
+++ b/PunchingBag/src/Arduino.java
@@ -179,5 +179,16 @@ public class Arduino implements Runnable {
}
+ public void write(byte[] bytes) throws IOException {
+ out.write(bytes);
+ }
+
+ public void write(byte b) throws IOException {
+ out.write(b);
+ }
+
+ public int read() throws IOException {
+ return in.read();
+ }
}
diff --git a/PunchingBag/src/PunchingBag.java b/PunchingBag/src/PunchingBag.java
index 0f08276..f39e666 100644
--- a/PunchingBag/src/PunchingBag.java
+++ b/PunchingBag/src/PunchingBag.java
@@ -1,5 +1,6 @@
import javax.swing.event.EventListenerList;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
@@ -20,7 +21,8 @@ public class PunchingBag implements Runnable {
private ArrayList<Effect> runningEffects = new ArrayList<Effect>();
- ButtonArduino buttonArduino = new ButtonArduino();
+ Arduino buttonArduino = new Arduino();
+ Arduino ledArduino = new Arduino();
public enum Colour {
None, Red, Yellow, Green
@@ -191,6 +193,7 @@ public class PunchingBag implements Runnable {
}
}
}
+ /*
int x = 7;
// TODO: Complete and test, or rethink the following?
for (int startY = 0; startY <= 4; startY++) {
@@ -205,7 +208,7 @@ public class PunchingBag implements Runnable {
.floor(y / 4)] | (1 << (7 - x)));
}
}
- }
+ }*/
}
/* Clears the led grid and stops all running effects */
@@ -253,6 +256,28 @@ public class PunchingBag implements Runnable {
}
}
}
+
+ try {
+ ledArduino.write(((byte)108));
+ ledArduino.write(((byte)101));
+ ledArduino.write(rawLeds);
+ } catch (IOException e1) {
+ e1.printStackTrace();
+ }
+
+ try {
+ while (true) {
+ int value = ledArduino.read();
+ if (value != -1) {
+ System.out.print(ledArduino.read());
+ } else {
+ break;
+ }
+ }
+ } catch (IOException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ }
if (ledsChanged) {
LEDListener[] LEDListeners = ledListenerList