From ba3448fb8093afd9d298cef1123a1bedfea13999 Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Wed, 7 Sep 2011 09:44:04 +0100 Subject: Added LEDMatrix.pde, this should be used to test the first matrix only! (at the moment). Also added font, this can be used only with java 1.70 and an eclipse maintantice build? --- PunchingBag/src/PunchingBag.java | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'PunchingBag/src/PunchingBag.java') diff --git a/PunchingBag/src/PunchingBag.java b/PunchingBag/src/PunchingBag.java index b36f562..0f08276 100644 --- a/PunchingBag/src/PunchingBag.java +++ b/PunchingBag/src/PunchingBag.java @@ -19,6 +19,8 @@ public class PunchingBag implements Runnable { boolean buttonsChanged = false; private ArrayList runningEffects = new ArrayList(); + + ButtonArduino buttonArduino = new ButtonArduino(); public enum Colour { None, Red, Yellow, Green @@ -27,6 +29,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(); @@ -45,6 +49,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]; @@ -70,7 +78,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; @@ -229,16 +238,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 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(); } -- cgit v1.2.3