Created
May 20, 2014 22:43
-
-
Save DapperFox/2acf023ec02d8b9e2d6b to your computer and use it in GitHub Desktop.
Touch Notifier
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package learnlejos; | |
import lejos.nxt.SensorPort; | |
import lejos.nxt.TouchSensor; | |
import java.util.ArrayList; | |
/** | |
* Created by blakebishop on 5/20/14. | |
*/ | |
public class TouchNotifier implements Runnable { | |
private ArrayList<ITouchListener> listeners; | |
private TouchSensor touchSensor = new TouchSensor(SensorPort.S1); | |
@Override | |
public void run() { | |
listeners = new ArrayList<>(); | |
while(true) { | |
if(touchSensor.isPressed()) | |
{ | |
for(ITouchListener listener : listeners) { | |
listener.changeState(); | |
} | |
} | |
} | |
} | |
public void register(ITouchListener listener) { | |
listeners.add(listener); | |
} | |
public void unregister(ITouchListener listener) { | |
listeners.remove(listener); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment