From a09647f50841e23e4783ef8c34faa9219054234f Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Wed, 7 Sep 2011 16:38:19 +0100 Subject: More arduino stuff. --- PunchingBag/src/Arduino.java | 11 +++++++++++ PunchingBag/src/PunchingBag.java | 29 +++++++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 2 deletions(-) (limited to 'PunchingBag') 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 runningEffects = new ArrayList(); - 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 -- cgit v1.2.3