#include <WiFi.h>
#include <WiFiClient.h>
#include <Ultrasonic.h>
#include "ThingSpeak.h"
///########### configuração do wifi
#define WIFI_SSID "Wokwi-GUEST"
#define WIFI_PASSWORD ""
#define WIFI_CHANNEL 6
int status = WL_IDLE_STATUS; // the Wifi radio's status
WiFiClient client;
// Configuração do thingspeak
const int myChannelNumber = 2334735;
const char* myApiKey = "GDZLKK6V93J91Z5K";
const char* server = "api.thingspeak.com";
#define BUTTON_PIN 4
// Ultrassonic
#define ECHO_PIN 19
#define TRIG_PIN 18
void setup() {
Serial.begin(115200);
pinMode(BUTTON_PIN, INPUT_PULLUP);
pinMode(LED_BUILTIN, OUTPUT);
pinMode(TRIG_PIN, OUTPUT);
pinMode(ECHO_PIN, INPUT);
}
int lastState = HIGH;
float readDistanceCM() {
digitalWrite(TRIG_PIN, LOW);
delayMicroseconds(2);
digitalWrite(TRIG_PIN, HIGH);
delayMicroseconds(10);
digitalWrite(TRIG_PIN, LOW);
int duration = pulseIn(ECHO_PIN, HIGH);
return duration * 0.034 / 2;
}
void loop() {
int value = digitalRead((BUTTON_PIN));
if (lastState != value) {
lastState = value;
if (value == HIGH) {
Serial.println(" released");
}
if (value == LOW) {
Serial.println(" pressed");
}
}
}