This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
en:iot:examples:buzzer [2020/07/20 11:26] – external edit 127.0.0.1 | en:iot:examples:buzzer [2024/03/12 16:19] (current) – heiko.pikner | ||
---|---|---|---|
Line 3: | Line 3: | ||
Needed libraries: | Needed libraries: | ||
- | < | + | < |
- | The code below will alert the buzz sound when values have been submitted | + | The code below will alert the buzz sound when values have been submitted |
<code c> | <code c> | ||
Line 18: | Line 18: | ||
*/ | */ | ||
+ | // Includes global variables and librarys that the Buzzer uses | ||
#include < | #include < | ||
#include < | #include < | ||
#include < | #include < | ||
+ | |||
+ | #define MODULE_TOPIC " | ||
+ | #define WIFI_NAME " | ||
+ | #define WIFI_PASSWORD " | ||
//Pin definition for the buzzer (GPIO15) | //Pin definition for the buzzer (GPIO15) | ||
Line 27: | Line 32: | ||
Buzzer buzzer(BUZZER_PIN); | Buzzer buzzer(BUZZER_PIN); | ||
+ | // Splitting string into smaller parts, so that the sound level and length can be read out | ||
// https:// | // https:// | ||
String getValue(String data, char separator, int index) | String getValue(String data, char separator, int index) | ||
Line 43: | Line 49: | ||
} | } | ||
} | } | ||
- | |||
return found> | return found> | ||
} | } | ||
Line 57: | Line 62: | ||
Serial.println(msg); | Serial.println(msg); | ||
- | String Note = getValue(msg,';', | + | |
- | String time = getValue(msg,';', | + | { |
- | + | | |
- | buzzer.sound(Note.toInt(), | + | String time = getValue(msg,';', |
+ | buzzer.sound(Note.toInt(), | ||
+ | } | ||
} | } | ||
Line 69: | Line 76: | ||
Serial.println(" | Serial.println(" | ||
// Subscribe to the topic " | // Subscribe to the topic " | ||
- | iot.subscribe(" | + | iot.subscribe(MODULE_TOPIC); |
iot.log(" | iot.log(" | ||
} | } | ||
Line 75: | Line 82: | ||
void setup() | void setup() | ||
{ | { | ||
- | Serial.begin(115200); | + | Serial.begin(115200); |
Serial.println(" | Serial.println(" | ||
+ | // | ||
+ | // | ||
// Print json config to serial | // Print json config to serial | ||
iot.printConfig(); | iot.printConfig(); | ||
// Initialize IoT library | // Initialize IoT library | ||
iot.setup(); | iot.setup(); | ||
- | // Initialize buzzer pin | ||
- | |||
} | } | ||
+ | //Main code, which runs in loop | ||
void loop() | void loop() | ||
{ | { | ||
// IoT behind the plan work, it should be periodically called | // IoT behind the plan work, it should be periodically called | ||
iot.handle(); | iot.handle(); | ||
- | delay(200); | + | delay(200); |
} | } | ||
+ | |||
</ | </ | ||