aboutsummaryrefslogtreecommitdiff
path: root/PunchingBag/src/uk/ac/open/punchingbag/examples/SimpleKeyboard.java
diff options
context:
space:
mode:
Diffstat (limited to 'PunchingBag/src/uk/ac/open/punchingbag/examples/SimpleKeyboard.java')
-rw-r--r--PunchingBag/src/uk/ac/open/punchingbag/examples/SimpleKeyboard.java18
1 files changed, 13 insertions, 5 deletions
diff --git a/PunchingBag/src/uk/ac/open/punchingbag/examples/SimpleKeyboard.java b/PunchingBag/src/uk/ac/open/punchingbag/examples/SimpleKeyboard.java
index b2d96a5..5a7b8fb 100644
--- a/PunchingBag/src/uk/ac/open/punchingbag/examples/SimpleKeyboard.java
+++ b/PunchingBag/src/uk/ac/open/punchingbag/examples/SimpleKeyboard.java
@@ -28,23 +28,30 @@ public class SimpleKeyboard implements ButtonListener, Runnable {
static PunchingBag bag = PunchingBag.getBag();
long lastActionTime = System.currentTimeMillis();
+ boolean noising = false;
public static void main(String[] args) {
- new SimpleKeyboard();
- }
-
- public SimpleKeyboard() {
- bag.addButtonListener(this);
try {
bag.connectToArduinos();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
+ new SimpleKeyboard();
+
+ }
+
+ public SimpleKeyboard() {
+ bag.addButtonListener(this);
+
new Thread (this).start();
}
public void buttonPressed(int x, int y) {
+ if (noising = true) {
+ bag.clearLEDs();
+ noising = false;
+ }
lastActionTime = System.currentTimeMillis();
System.out.println("Button Pressed: " + x + " " + y);
if (y < 3) {
@@ -99,6 +106,7 @@ public class SimpleKeyboard implements ButtonListener, Runnable {
while (true) {
if ((System.currentTimeMillis() - lastActionTime) > 4000) {
bag.noise(new Rectangle(0, 0, 9, 20));
+ noising = true;
}
}