Skip to content

Commit

Permalink
Earthquake Buzzer Alarm
Browse files Browse the repository at this point in the history
Signed-off-by: John Walicki <walicki@us.ibm.com>
  • Loading branch information
johnwalicki committed Dec 20, 2020
1 parent 87aa1c2 commit 6928ee0
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions firmware/WatsonIoT/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,14 @@ void NeoPixelStatus( int );
#define LED_FIRMWARE_DFU 8 // Yellow
#define LED_ERROR 9 // Red

// --------------------------------------------------------------------------------------------
// Buzzer Alarm
void Alarm();
int freq = 4000;
int channel = 0;
int resolution = 8;
int io = 5;

// --------------------------------------------------------------------------------------------
void IRAM_ATTR isr_adxl() {
fifoFull = true;
Expand Down Expand Up @@ -198,9 +206,10 @@ void callback(char* topic, byte* payload, unsigned int length) {
if ( strcmp(topic, MQTT_TOPIC_ALARM) == 0 ) {
// Sound the Buzzer & Blink the LED
Serial.println("Earthquake Alarm!");
for( int i=0;i<4;i++){
for( int i=0;i<10;i++) {
delay(500);
NeoPixelStatus( LED_ERROR ); // Alarm - blink red
Alarm();
}
} else if ( strcmp(topic, MQTT_TOPIC_FWCHECK) == 0 ) {
// Remote message received to check for new firmware
Expand Down Expand Up @@ -742,8 +751,10 @@ void setup() {
adxl355.initSPI(*spi1);
StartADXL355();

pinMode(5, OUTPUT); // GARETH declare buzzer
digitalWrite(5, LOW); // GARETH turn off buzzer
//pinMode(5, OUTPUT); // GARETH declare buzzer
//digitalWrite(5, LOW); // GARETH turn off buzzer
ledcSetup(channel, freq, resolution);
ledcAttachPin(io, channel);
}


Expand Down Expand Up @@ -1068,3 +1079,16 @@ void NeoPixelStatus( int status ) {
}
strip.show(); // Send the updated pixel color to the hardware
}


// Generate Buzzer sounds
void Alarm() {
ledcWrite(channel, 50);
delay(100);
ledcWrite(channel, 500);
delay(100);
ledcWrite(channel, 2000);
delay(100);
ledcWrite(channel, 4000);
delay(100);
}

0 comments on commit 6928ee0

Please sign in to comment.