Skip to content

Commit c4cb35f

Browse files
author
brentru
committed
esp32-specific tone function in io_home_security.ino
1 parent c320f1c commit c4cb35f

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

examples/io_home_series/io_home_security/io_home_security.ino

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ AdafruitIO_Feed *frontDoor = io.feed("front-door");
8787
// `motion-detector` feed
8888
AdafruitIO_Feed *motionFeed = io.feed("motion-detector");
8989
// `home-alarm` feed
90-
AdafruitIO_Feed *alarm = io.feed("home-alarm");
90+
AdafruitIO_Feed *homeAlarm = io.feed("home-alarm");
9191
// 'tvoc' feed
9292
AdafruitIO_Feed *tvocFeed = io.feed("tvoc");
9393
// 'eco2' feed
@@ -106,7 +106,7 @@ void setup() {
106106
io.connect();
107107

108108
// attach a message handler for the `home-alarm` feed
109-
alarm->onMessage(handleAlarm);
109+
homeAlarm->onMessage(handleAlarm);
110110
// subscribe to lighting feeds and register message handlers
111111
indoorLights->onMessage(indoorLightHandler);
112112
outdoorLights->onMessage(outdoorLightHandler);
@@ -159,7 +159,14 @@ void loop(){
159159
void playAlarmAnimation() {
160160
// plays the alarm piezo buzzer and turn on/off neopixels
161161
Serial.println("ALARM TRIGGERED!");
162-
tone(piezoPin, 220, 2);
162+
163+
#if defined(ARDUINO_ARCH_ESP32)
164+
// ESP32 doesn't use native tone() function
165+
ledcWriteTone(piezoPin, 220);
166+
#else
167+
tone(piezoPin, 220, 2);
168+
#endif
169+
163170
for(int i=0; i<JEWEL_PIXEL_COUNT; ++i) {
164171
strip.setPixelColor(i, 255, 0, 0);
165172
}
@@ -295,4 +302,4 @@ void getTime() {
295302
Serial.print(minutes);
296303
Serial.print(":");
297304
Serial.println(seconds);
298-
}
305+
}

0 commit comments

Comments
 (0)