1 | /*
|
---|
2 | Esplora Remote
|
---|
3 |
|
---|
4 | This sketch allows to test all the Esplora's peripherals.
|
---|
5 | It is also used with the ProcessingStart sketch (for Processing).
|
---|
6 |
|
---|
7 | When uploaded, you can open the Serial monitor and write one of
|
---|
8 | the following commands (without quotes) to get an answer:
|
---|
9 |
|
---|
10 | "D": prints the current value of all sensors, separated by a comma.
|
---|
11 | See the dumpInputs() function below to get the meaning of
|
---|
12 | each value.
|
---|
13 |
|
---|
14 | "Rxxx"
|
---|
15 | "Gxxx"
|
---|
16 | "Bxxx": set the color of the RGB led. For example, write "R255"
|
---|
17 | to turn on the red to full brightness, "G128" to turn
|
---|
18 | the green to half brightness, or "G0" to turn off
|
---|
19 | the green channel.
|
---|
20 |
|
---|
21 | "Txxxx": play a tone with the buzzer. The number is the
|
---|
22 | frequency, e.g. "T440" plays the central A note.
|
---|
23 | Write "T0" to turn off the buzzer.
|
---|
24 |
|
---|
25 |
|
---|
26 | Created on 22 november 2012
|
---|
27 | By Enrico Gueli <enrico.gueli@gmail.com>
|
---|
28 | Modified 23 Dec 2012
|
---|
29 | by Tom Igoe
|
---|
30 | */
|
---|
31 |
|
---|
32 | #include <Esplora.h>
|
---|
33 |
|
---|
34 | void setup() {
|
---|
35 | while (!Serial); // needed for Leonardo-based board like Esplora
|
---|
36 | Serial.begin(9600);
|
---|
37 | }
|
---|
38 |
|
---|
39 | void loop() {
|
---|
40 | if (Serial.available())
|
---|
41 | parseCommand();
|
---|
42 | }
|
---|
43 |
|
---|
44 | /*
|
---|
45 | * This function reads a character from the serial line and
|
---|
46 | * decide what to do next. The "what to do" part is given by
|
---|
47 | * function it calls (e.g. dumpInputs(), setRed() and so on).
|
---|
48 | */
|
---|
49 | void parseCommand() {
|
---|
50 | char cmd = Serial.read();
|
---|
51 | switch (cmd) {
|
---|
52 | case 'D':
|
---|
53 | dumpInputs();
|
---|
54 | break;
|
---|
55 | case 'R':
|
---|
56 | setRed();
|
---|
57 | break;
|
---|
58 | case 'G':
|
---|
59 | setGreen();
|
---|
60 | break;
|
---|
61 | case 'B':
|
---|
62 | setBlue();
|
---|
63 | break;
|
---|
64 | case 'T':
|
---|
65 | setTone();
|
---|
66 | break;
|
---|
67 | }
|
---|
68 | }
|
---|
69 |
|
---|
70 | void dumpInputs() {
|
---|
71 | Serial.print(Esplora.readButton(SWITCH_1));
|
---|
72 | Serial.print(',');
|
---|
73 | Serial.print(Esplora.readButton(SWITCH_2));
|
---|
74 | Serial.print(',');
|
---|
75 | Serial.print(Esplora.readButton(SWITCH_3));
|
---|
76 | Serial.print(',');
|
---|
77 | Serial.print(Esplora.readButton(SWITCH_4));
|
---|
78 | Serial.print(',');
|
---|
79 | Serial.print(Esplora.readSlider());
|
---|
80 | Serial.print(',');
|
---|
81 | Serial.print(Esplora.readLightSensor());
|
---|
82 | Serial.print(',');
|
---|
83 | Serial.print(Esplora.readTemperature(DEGREES_C));
|
---|
84 | Serial.print(',');
|
---|
85 | Serial.print(Esplora.readMicrophone());
|
---|
86 | Serial.print(',');
|
---|
87 | Serial.print(Esplora.readJoystickSwitch());
|
---|
88 | Serial.print(',');
|
---|
89 | Serial.print(Esplora.readJoystickX());
|
---|
90 | Serial.print(',');
|
---|
91 | Serial.print(Esplora.readJoystickY());
|
---|
92 | Serial.print(',');
|
---|
93 | Serial.print(Esplora.readAccelerometer(X_AXIS));
|
---|
94 | Serial.print(',');
|
---|
95 | Serial.print(Esplora.readAccelerometer(Y_AXIS));
|
---|
96 | Serial.print(',');
|
---|
97 | Serial.print(Esplora.readAccelerometer(Z_AXIS));
|
---|
98 | Serial.println();
|
---|
99 | }
|
---|
100 |
|
---|
101 | void setRed() {
|
---|
102 | Esplora.writeRed(Serial.parseInt());
|
---|
103 | }
|
---|
104 |
|
---|
105 | void setGreen() {
|
---|
106 | Esplora.writeGreen(Serial.parseInt());
|
---|
107 | }
|
---|
108 |
|
---|
109 | void setBlue() {
|
---|
110 | Esplora.writeBlue(Serial.parseInt());
|
---|
111 | }
|
---|
112 |
|
---|
113 | void setTone() {
|
---|
114 | Esplora.tone(Serial.parseInt());
|
---|
115 | }
|
---|
116 |
|
---|