1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package motej.demos.buttons;
17
18 import motej.Mote;
19 import motej.MoteFinder;
20 import motej.event.CoreButtonEvent;
21 import motej.event.CoreButtonListener;
22
23
24
25
26
27
28 public class ButtonsDemo {
29
30 public static void main(String[] args) {
31 System.out.println("press 'q' to quit.");
32
33 Mote mote = MoteFinder.getMoteFinder().findMote();
34 mote.addCoreButtonListener(new CoreButtonListener() {
35
36 public void buttonPressed(CoreButtonEvent evt) {
37 if (evt.isButtonAPressed()) {
38 System.out.println("Button A pressed!");
39 }
40 if (evt.isButtonBPressed()) {
41 System.out.println("Button B pressed!");
42 }
43 if (evt.isNoButtonPressed()) {
44 System.out.println("No button pressed.");
45 }
46 }
47
48 });
49
50 while (true) {
51 String line = System.console().readLine();
52 if (line.indexOf("q") != -1) {
53 mote.disconnect();
54 System.exit(0);
55 }
56 }
57 }
58 }