Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: Cayenne-MQTT-mbed mbed Servo X_NUCLEO_IDW01M1v2 NetworkSocketAPI HCSR04
Revision 13:3a299d5a7057, committed 2019-08-02
- Comitter:
- stiotchallenge
- Date:
- Fri Aug 02 07:29:10 2019 +0000
- Parent:
- 12:dd98953c0a6d
- Commit message:
- Module 4: Servomotor
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file | 
diff -r dd98953c0a6d -r 3a299d5a7057 main.cpp
--- a/main.cpp	Wed Jul 17 05:10:39 2019 +0000
+++ b/main.cpp	Fri Aug 02 07:29:10 2019 +0000
@@ -7,7 +7,6 @@
 #include "CayenneMQTTClient.h"
 #include "MQTTNetworkIDW01M1.h"
 #include "SpwfInterface.h"
-#include "hcsr04.h"
 #include "Servo.h"
 
 // WiFi network info.
@@ -27,7 +26,6 @@
 DigitalOut led1(LED1);
 DigitalOut ledGreen(D11);
 DigitalOut ledRed(D12);
-HCSR04 sensor(D7, D6);
 Servo myservo(D10);
 
 int iotvalue;
@@ -47,27 +45,19 @@
 
 //    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;   
+    if (button1) {
         myservo = 1; //tutup
         wait(0.2);
         openclose = 0;
     }
-    if (distance <50) {
-        ledGreen = 1;
-        ledRed = 0;
+    else {
         myservo = 0; //buka
         wait(0.2);
         openclose = 1;
     }
     
-    timer = publishData(timer, ledGreen, openclose);
+    timer = publishData(timer, button1, openclose);
     return timer;
 }