Skip to content
This repository was archived by the owner on Mar 17, 2025. It is now read-only.

Commit 9f146de

Browse files
committed
Added buttons and led logic
1 parent 1c422b9 commit 9f146de

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

examples/FirebaseSerialClient/FirebaseSerialClient.ino

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,22 @@
2323
// the stored value.
2424
// This example touches most of the basic calls over the serial interface.
2525

26-
// Set these parameters.
26+
const int sendButtonPin = 4;
27+
const int flashButtonPin = 5;
28+
const int ledPin = 6;
2729

30+
// Set these parameters.
2831
const String network_ssid = "";
2932
const String host = "";
3033
const String auth = "";
3134

3235
bool initialized = false;
3336

3437
void setup() {
38+
pinMode(sendButtonPin, INPUT);
39+
pinMode(flashButtonPin, INPUT);
40+
pinMode(ledPin, OUTPUT);
41+
3542
// Connect to pc over usb.
3643
Serial.begin(9600);
3744

@@ -63,14 +70,14 @@ void loop() {
6370
return;
6471
}
6572

66-
if (SendButtonDown() && FlashButtonDown()) {
73+
if (digitalRead(sendButtonPin) && digitalRead(flashButtonPin)) {
6774
dataPrintLn("REMOVE /led_flashes");
6875
String response = dataReadLn();
6976
if (response != "+OK") {
7077
debugPrintLn("Error during REMOVE: " + response);
7178
}
7279

73-
} else if (SendButtonDown()) {
80+
} else if (digitalRead(sendButtonPin)) {
7481
debugPrintLn("Sending random number.");
7582
int flashes = random(10);
7683

@@ -91,33 +98,27 @@ void loop() {
9198

9299
debugPrintLn("Done sending random number.");
93100

94-
} else if (FlashButtonDown()) {
101+
} else if (digitalRead(flashButtonPin)) {
95102
debugPrintLn("Flashing LED.");
96103
dataPrintLn(String("GET# /led_flashes"));
97104
if (dataReadType() == '-') {
98105
debugPrintLn("Error during GET: " + dataReadLn());
99106
}
100107

101108
int flashes = atoi(dataReadLn().c_str());
102-
FlashLed(flashes);
109+
flashLed(flashes);
103110

104111
debugPrintLn("Done flashing LED.");
105112
}
106113
}
107114

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+
}
121122
}
122123

123124
void debugPrintLn(const String& message) {

0 commit comments

Comments
 (0)