Servomotor-Button

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 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
--- 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;
 }