23
23
// the stored value.
24
24
// This example touches most of the basic calls over the serial interface.
25
25
26
- // Set these parameters.
26
+ const int sendButtonPin = 4 ;
27
+ const int flashButtonPin = 5 ;
28
+ const int ledPin = 6 ;
27
29
30
+ // Set these parameters.
28
31
const String network_ssid = " " ;
29
32
const String host = " " ;
30
33
const String auth = " " ;
31
34
32
35
bool initialized = false ;
33
36
34
37
void setup () {
38
+ pinMode (sendButtonPin, INPUT);
39
+ pinMode (flashButtonPin, INPUT);
40
+ pinMode (ledPin, OUTPUT);
41
+
35
42
// Connect to pc over usb.
36
43
Serial.begin (9600 );
37
44
@@ -63,14 +70,14 @@ void loop() {
63
70
return ;
64
71
}
65
72
66
- if (SendButtonDown ( ) && FlashButtonDown ( )) {
73
+ if (digitalRead (sendButtonPin ) && digitalRead (flashButtonPin )) {
67
74
dataPrintLn (" REMOVE /led_flashes" );
68
75
String response = dataReadLn ();
69
76
if (response != " +OK" ) {
70
77
debugPrintLn (" Error during REMOVE: " + response);
71
78
}
72
79
73
- } else if (SendButtonDown ( )) {
80
+ } else if (digitalRead (sendButtonPin )) {
74
81
debugPrintLn (" Sending random number." );
75
82
int flashes = random (10 );
76
83
@@ -91,33 +98,27 @@ void loop() {
91
98
92
99
debugPrintLn (" Done sending random number." );
93
100
94
- } else if (FlashButtonDown ( )) {
101
+ } else if (digitalRead (flashButtonPin )) {
95
102
debugPrintLn (" Flashing LED." );
96
103
dataPrintLn (String (" GET# /led_flashes" ));
97
104
if (dataReadType () == ' -' ) {
98
105
debugPrintLn (" Error during GET: " + dataReadLn ());
99
106
}
100
107
101
108
int flashes = atoi (dataReadLn ().c_str ());
102
- FlashLed (flashes);
109
+ flashLed (flashes);
103
110
104
111
debugPrintLn (" Done flashing LED." );
105
112
}
106
113
}
107
114
108
- bool SendButtonDown () {
109
- // TODO Add detection for button on pin.
110
- return false ;
111
- }
112
-
113
- bool FlashButtonDown () {
114
- // TODO Add detection for button on pin.
115
- return false ;
116
- }
117
-
118
- void FlashLed (int times) {
119
- // TODO Add logic to flash led at high frequency <500ms between
120
- // flashes so we don't take too long.
115
+ void flashLed (int times) {
116
+ for (int i=0 ; i < times; i++) {
117
+ digitalWrite (ledPin, HIGH);
118
+ delay (200 );
119
+ digitalWrite (ledPin, LOW);
120
+ delay (300 );
121
+ }
121
122
}
122
123
123
124
void debugPrintLn (const String& message) {
0 commit comments