#define THINGER_SERIAL_DEBUG
#include <ThingerESP32.h>
#define username "Wizardh6lic"
#define device_id "wizard"
#define credential "12345678"
#define SSID "Wokwi-GUEST"
#define password ""
#define lampu 21
#define trig 13
#define echo 12
ThingerESP32 thing(username, device_id, credential);
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32!");
pinMode(trig, OUTPUT);
pinMode(echo, INPUT);
pinMode(lampu, OUTPUT);
thing.add_wifi(SSID, password);
thing["lampu"] << digitalPin(lampu);
thing["Ultrasonic"] >> [](pson& out) {
digitalWrite(trig, HIGH);
delayMicroseconds(10);
digitalWrite(trig, LOW);
long waktu = pulseIn(echo, HIGH);
double jarak = waktu/58;
out = jarak;
};
}
void loop() {
// put your main code here, to run repeatedly:
thing.handle();
//Serial.println(jarak);
//Serial.println(200 - jarak);
}