From 852306221f4adcaf2ea9edb68153ea6090b68803 Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Mon, 12 Sep 2011 09:54:03 +0100 Subject: Commit to move to other laptop due to technical dificulties. --- Arduino/ButtonMatrix/ButtonMatrix.pde | 112 +++++++++++++++++++--------------- Arduino/LEDMatrix/LEDMatrix.pde | 28 +-------- PunchingBag/src/PunchingBag.java | 57 ++++++++++++----- PunchingBag/src/PunchingBagGUI.java | 4 +- 4 files changed, 109 insertions(+), 92 deletions(-) diff --git a/Arduino/ButtonMatrix/ButtonMatrix.pde b/Arduino/ButtonMatrix/ButtonMatrix.pde index 99c879d..702e487 100755 --- a/Arduino/ButtonMatrix/ButtonMatrix.pde +++ b/Arduino/ButtonMatrix/ButtonMatrix.pde @@ -4,12 +4,21 @@ 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) -const int selfTest = A0; +const int agroundpin = A4; // analog input pin 4 -- ground +const int apowerpin = A5; // analog input pin 5 -- voltage +const int axpin = A3; // x-axis of the accelerometer +const int aypin = A2; // y-axis +const int azpin = A1; // z-axis (only on 3-axis models) +const int aselfTest = A0; + +// these constants describe the pins for the acellarometer . They won't change: +const int bgroundpin = A12; // analog input pin 4 -- ground +const int bpowerpin = A13; // analog input pin 5 -- voltage +const int bxpin = A11; // x-axis of the accelerometer +const int bypin = A10; // y-axis +const int bzpin = A9; // z-axis (only on 3-axis models) +const int bselfTest = A8; + const int id = 1; @@ -20,28 +29,28 @@ const int id = 1; */ char keys[COLS][ROWS] = { { - 1, 9, 17, 25, 33, 41, 49, 57, 65, 73, 81, 89, 97, 105, 113, 121, 129, 137, 145 } + 1, 9, 17, 25, 33, 41, 49, 57, 65, 73, 81, 89, 97, 105, 113, 121, 129, 137, 145 } , { - 2, 10, 18, 26, 34, 42, 50, 58, 66, 74, 82, 90, 98, 106, 114, 122, 130, 138, 146 } + 2, 10, 18, 26, 34, 42, 50, 58, 66, 74, 82, 90, 98, 106, 114, 122, 130, 138, 146 } , { - 3, 11, 19, 27, 35, 43, 51, 59, 67, 75, 83, 91, 99, 107, 115, 123, 131, 139, 147 } + 3, 11, 19, 27, 35, 43, 51, 59, 67, 75, 83, 91, 99, 107, 115, 123, 131, 139, 147 } , { - 4, 12, 20, 28, 36, 44, 52, 60, 68, 76, 84, 92, 100, 108, 116, 124, 132, 140, 148 } + 4, 12, 20, 28, 36, 44, 52, 60, 68, 76, 84, 92, 100, 108, 116, 124, 132, 140, 148 } , { - 5, 13, 21, 29, 37, 45, 53, 61, 69, 77, 85, 93, 101, 109, 117, 125, 133, 141, 149 } + 5, 13, 21, 29, 37, 45, 53, 61, 69, 77, 85, 93, 101, 109, 117, 125, 133, 141, 149 } , { - 6, 14, 22, 30, 38, 46, 54, 62, 70, 78, 86, 94, 102, 110, 118, 126, 134, 142, 150 } + 6, 14, 22, 30, 38, 46, 54, 62, 70, 78, 86, 94, 102, 110, 118, 126, 134, 142, 150 } , { - 7, 15, 23, 31, 39, 47, 55, 63, 71, 79, 87, 95, 103, 111, 119, 127, 135, 143, 151 } + 7, 15, 23, 31, 39, 47, 55, 63, 71, 79, 87, 95, 103, 111, 119, 127, 135, 143, 151 } , { - 8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, 104, 112, 120, 128, 136, 144, 152 } + 8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, 104, 112, 120, 128, 136, 144, 152 } }; byte colPins[COLS] = { @@ -58,18 +67,25 @@ Keypad keypad = Keypad( makeKeymap(keys), colPins, rowPins, COLS, ROWS); void setup(){ Serial.begin(9600); - Serial.println("Go"); + //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); + pinMode(agroundpin, OUTPUT); + pinMode(apowerpin, OUTPUT); + //pinMode(selfTest, OUTPUT); + digitalWrite(agroundpin, LOW); + digitalWrite(apowerpin, HIGH); + //digitalWrite(selfTest, HIGH); + pinMode(bgroundpin, OUTPUT); + pinMode(bpowerpin, OUTPUT); //pinMode(selfTest, OUTPUT); - digitalWrite(groundpin, LOW); - digitalWrite(powerpin, HIGH); + digitalWrite(bgroundpin, LOW); + digitalWrite(bpowerpin, HIGH); //digitalWrite(selfTest, HIGH); + } /* Send numbers back and forth to test the integrity of the serial communication Computer sends the first byte @@ -89,37 +105,37 @@ boolean runSerialTest() { } void loop(){ - //if (Serial.peek() == 0x49) { - Serial.write(37); - //Serial.write(Serial.read()); - /*if (Serial.read() == 0x44) { - Serial.write(id); - }*/ - //} else { - // Serial.write(1); - //Serial.write(Serial.read()); - //} - - /*char customKey = keypad.getKey(); - int customKeyInt = customKey; - if (customKeyInt < 0) customKeyInt += 256; - 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(10);*/ + + Serial.write('B'); + Serial.print(" "); + char customKey = keypad.getKey(); + int customKeyInt = customKey; + if (customKeyInt < 0) customKeyInt += 256; + if (customKey != NO_KEY){ + Serial.print(customKeyInt); + } + Serial.println(); + + Serial.write('A'); + Serial.print(" "); + // print the sensor values: + Serial.print(analogRead(axpin)); + // print a tab between values: + Serial.print(" "); + Serial.print(analogRead(aypin)); + Serial.print(" "); + // print the sensor values: + Serial.print(analogRead(bxpin)); + // print a tab between values: + Serial.print(" "); + Serial.println(analogRead(bypin)); + // print a tab between values: + // delay before next reading: + //delay(10);*/ + delay(100); } + diff --git a/Arduino/LEDMatrix/LEDMatrix.pde b/Arduino/LEDMatrix/LEDMatrix.pde index 18a00ae..4a07bfc 100644 --- a/Arduino/LEDMatrix/LEDMatrix.pde +++ b/Arduino/LEDMatrix/LEDMatrix.pde @@ -24,32 +24,8 @@ void setup ( ) void loop ( ) { - int timer = 0; - - if (Serial.read() == ((byte)108)) { - Serial.println("L Recieved"); - while (Serial.peek() == -1) { - } - if (Serial.read() == ((byte)101)) { - while (Serial.peek() == -1) { - } - Serial.println("E recieved"); - for (int i = 0; i < (chips*8); i++) { - while (Serial.peek() == -1) { - } - buffer[i] = Serial.read(); - - Serial.println(buffer[i]); - - } - Serial.println("Buffer Recieved"); - - - } - - - - + for (int i=0; i<(chips * 8); i++) { + buffer[i] = 0b10101010;//random(-128,127); // Just Green } matrix.Update(); } diff --git a/PunchingBag/src/PunchingBag.java b/PunchingBag/src/PunchingBag.java index 198e709..85553a5 100644 --- a/PunchingBag/src/PunchingBag.java +++ b/PunchingBag/src/PunchingBag.java @@ -346,9 +346,20 @@ public class PunchingBag implements Runnable { } return true; } + + private void readAccelData(String data) { + //System.out.print("Data: "); + System.out.println(data); + //String[] nums = data.split(" "); + /*System.out.println(nums); + for (int x=0; x<4; x++) { + System.out.println(nums[x]); + }*/ + } public void run() { while (true) { + //System.out.println("R"); synchronized (leds) { clearLEDGrid(); @@ -373,29 +384,43 @@ public class PunchingBag implements Runnable { if (buttonArduino.in != null) { try { - int read = buttonArduino.read(); - if (read != -1) { - System.out.println(read); + int read; + while ((read = buttonArduino.read()) != -1) { + //System.out.print((char) read); + if ((char) read == 'A') { + String str = ""; + //StringBuilder sb = new StringBuilder(20); + while ((read = buttonArduino.read()) != '\n') { + str = str + String.valueOf((char) read); + //sb.append((char) read); + } + //System.out.println(""); + readAccelData(str); + //String[] nums = sbString.trim().split(" "); + //System.out.println(nums); + //for (int x=0; x<4; x++) { + // System.out.println(nums[x]); + //} + } else { + //System.out.println((char) read); + } + //System.out.print("|"); } - byte[] bA = { 0x49 }; - if (Math.random() > 0.9) - buttonArduino.write(bA); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } - /* - * 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 (ledArduino.out != null) { + try { + ledArduino.write(((byte) 108)); + ledArduino.write(((byte) 101)); + ledArduino.write(rawLeds); + } catch (IOException e1) { + e1.printStackTrace(); + } + }*/ if (ledsChanged) { LEDListener[] LEDListeners = ledListenerList diff --git a/PunchingBag/src/PunchingBagGUI.java b/PunchingBag/src/PunchingBagGUI.java index aacb2ac..9a23741 100644 --- a/PunchingBag/src/PunchingBagGUI.java +++ b/PunchingBag/src/PunchingBagGUI.java @@ -184,7 +184,7 @@ public class PunchingBagGUI implements MouseListener, MouseMotionListener, @Override public void serialWriteEvent(byte b) { - buttonOut.append(String.valueOf(b)); + buttonOut.append(String.valueOf((char) b)); } @Override @@ -195,7 +195,7 @@ public class PunchingBagGUI implements MouseListener, MouseMotionListener, @Override public void serialReadEvent(int b) { if (b != -1) - buttonIn.append(String.valueOf(b)); + buttonIn.append(String.valueOf((char) b)); } } -- cgit v1.2.3