Projet IoT - Fire Detector CS

Dependencies:   BSP_B-L475E-IOT01

Files at this revision

API Documentation at this revision

Comitter:
GuilhermeLubk
Date:
Tue Oct 13 12:46:38 2020 +0000
Parent:
0:e84b46bbec77
Commit message:
New member : Buzzer;

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Tue Oct 13 12:24:59 2020 +0000
+++ b/main.cpp	Tue Oct 13 12:46:38 2020 +0000
@@ -40,6 +40,9 @@
 DigitalOut  led1(LED1, 1);
 DigitalOut  led2(LED2, 1);
 
+//Buzzer
+PwmOut buzzer(D9);
+
 //Interruptions
 InterruptIn button(D3);
 InterruptIn IR(D7);
@@ -107,6 +110,7 @@
         printf("\nNum of positive readings: %d\n\r", numReadings);
 
         if(numReadings >= 5) {
+            buzzer.write(1.0f);
             printf("\nFIRE DETECTED - SENDING DATA\n\r");
             IR.rise(NULL);
             led1 = 1;
@@ -135,6 +139,7 @@
 
             while(true) {
                 
+                buzzer.write(1.0f);
                 // Open a socket on the network interface, and create a TCP connection to thingspeaks.com
                 socket.open(net);
                 response = socket.connect("api.thingspeak.com", 80);
@@ -179,6 +184,7 @@
                         printf("sent %d [%.*s]\n", response, strstr(sbuffer, "\r\n")-sbuffer, sbuffer);
                     }
                 }
+                 buzzer.write(0.8f);
 
                 // Receive a simple http response and print out the response line
                 char rbuffer[64];
@@ -190,6 +196,7 @@
                 }
                 // Close the socket to return its memory and bring down the network interface
                 socket.close();
+               
             }
 
 
@@ -213,7 +220,8 @@
 
 int main()
 {
-
+    buzzer.period(0.5f);      // 4 second period
+    buzzer.write(0.0f);
     led1 = 0;
     led2 = 0;
     thread.start(mbed::callback(main_routine));