Ultrasonic

Dependencies:   Cayenne-MQTT-mbed mbed Servo X_NUCLEO_IDW01M1v2 NetworkSocketAPI HCSR04

Files at this revision

API Documentation at this revision

Comitter:
stiotchallenge
Date:
Fri Aug 02 06:51:30 2019 +0000
Parent:
12:dd98953c0a6d
Commit message:
Module 3: Ultrasonic

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r dd98953c0a6d -r c5911ceac9ab main.cpp
--- a/main.cpp	Wed Jul 17 05:10:39 2019 +0000
+++ b/main.cpp	Fri Aug 02 06:51:30 2019 +0000
@@ -8,7 +8,7 @@
 #include "MQTTNetworkIDW01M1.h"
 #include "SpwfInterface.h"
 #include "hcsr04.h"
-#include "Servo.h"
+
 
 // WiFi network info.
 char* ssid = "iPhone";
@@ -28,7 +28,7 @@
 DigitalOut ledGreen(D11);
 DigitalOut ledRed(D12);
 HCSR04 sensor(D7, D6);
-Servo myservo(D10);
+
 
 int iotvalue;
 
@@ -45,29 +45,20 @@
     led1 = 0;
     wait(0.2);
 
-//    ledGreen = iotvalue;
     
-//ULTRASONIC + SERVO/////////////////////////////
-    int openclose;
     long distance = sensor.distance();   
     printf("distance  %d  \n",distance);
     wait(1.0); // 1 sec
     if (distance > 50) {
         ledGreen = 0;
         ledRed = 1;   
-        myservo = 1; //tutup
-        wait(0.2);
-        openclose = 0;
     }
     if (distance <50) {
         ledGreen = 1;
         ledRed = 0;
-        myservo = 0; //buka
-        wait(0.2);
-        openclose = 1;
     }
     
-    timer = publishData(timer, ledGreen, openclose);
+    timer = publishData(timer, ledGreen, ledRed);
     return timer;
 }