Skip to content

Commit f08b286

Browse files
committed
Changed GPIO PIN #defines for LED and BUTTON
1 parent 7fc79e6 commit f08b286

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

examples/Switch/Switch.ino

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@
4141
#define SWITCH_ID "YOUR-DEVICE-ID" // Should look like "5dc1564130xxxxxxxxxxxxxx"
4242
#define BAUD_RATE 9600 // Change baudrate to your need
4343

44-
#define BTN_FLASH 0
44+
#define BUTTON_PIN 0 // GPIO for BUTTON (inverted: LOW = pressed, HIGH = released)
45+
#define LED_PIN 2 // GPIO for LED (inverted)
4546

4647
bool myPowerState = false;
4748
unsigned long lastBtnPress = 0;
@@ -62,19 +63,19 @@ unsigned long lastBtnPress = 0;
6263
bool onPowerState(const String &deviceId, bool &state) {
6364
Serial.printf("Device %s turned %s (via SinricPro) \r\n", deviceId.c_str(), state?"on":"off");
6465
myPowerState = state;
65-
digitalWrite(LED_BUILTIN, myPowerState?LOW:HIGH);
66+
digitalWrite(LED_PIN, myPowerState?LOW:HIGH);
6667
return true; // request handled properly
6768
}
6869

6970
void handleButtonPress() {
7071
unsigned long actualMillis = millis(); // get actual millis() and keep it in variable actualMillis
71-
if (digitalRead(BTN_FLASH) == LOW && actualMillis - lastBtnPress > 1000) { // is button pressed (inverted logic! button pressed = LOW) and debounced?
72+
if (digitalRead(BUTTON_PIN) == LOW && actualMillis - lastBtnPress > 1000) { // is button pressed (inverted logic! button pressed = LOW) and debounced?
7273
if (myPowerState) { // flip myPowerState: if it was true, set it to false, vice versa
7374
myPowerState = false;
7475
} else {
7576
myPowerState = true;
7677
}
77-
digitalWrite(LED_BUILTIN, myPowerState?LOW:HIGH); // if myPowerState indicates device turned on: turn on led (builtin led uses inverted logic: LOW = LED ON / HIGH = LED OFF)
78+
digitalWrite(LED_PIN, myPowerState?LOW:HIGH); // if myPowerState indicates device turned on: turn on led (builtin led uses inverted logic: LOW = LED ON / HIGH = LED OFF)
7879

7980
// get Switch device back
8081
SinricProSwitch& mySwitch = SinricPro[SWITCH_ID];
@@ -96,7 +97,7 @@ void setupWiFi() {
9697
delay(250);
9798
}
9899
IPAddress localIP = WiFi.localIP();
99-
Serial.printf("connected!\r\n[WiFi]: IP-Address is %d.%d.%d.%d\r\n", localIP[0], localIP[1], localIP[2], localIP[3]);
100+
Serial.printf("connected!\r\n[WiFi]: IP-Address is %s\r\n", localIP[0], localIP[1], localIP[2], localIP[3]);
100101
}
101102

102103
// setup function for SinricPro
@@ -115,9 +116,9 @@ void setupSinricPro() {
115116

116117
// main setup function
117118
void setup() {
118-
pinMode(BTN_FLASH, INPUT_PULLUP); // GPIO 0 as input, pulled high
119-
pinMode(LED_BUILTIN, OUTPUT); // define LED GPIO as output
120-
digitalWrite(LED_BUILTIN, HIGH); // turn off LED on bootup
119+
pinMode(BUTTON_PIN, INPUT_PULLUP); // GPIO 0 as input, pulled high
120+
pinMode(LED_PIN, OUTPUT); // define LED GPIO as output
121+
digitalWrite(LED_PIN, HIGH); // turn off LED on bootup
121122

122123
Serial.begin(BAUD_RATE); Serial.printf("\r\n\r\n");
123124
setupWiFi();

0 commit comments

Comments
 (0)