buzzer/sketch_may21a/sketch_may21a.ino

64 lines
1.1 KiB
Arduino
Raw Normal View History

2024-05-22 11:49:17 +00:00
#include <WiFi.h>
#include <WiFiClient.h>
#include <WebServer.h>
const char* ssid = "Decentrala";
const char* password = "";
IPAddress local_IP(192, 168, 6, 102);
IPAddress gateway(192, 168, 6, 1);
IPAddress subnet(255, 255, 255, 0);
IPAddress primaryDNS(192, 168, 6, 1);
IPAddress secondaryDNS(9, 9, 9, 9);
WebServer server(80);
const int requestEnterPin = 36;
const int openDoorPin = 32;
2024-05-22 11:49:17 +00:00
int requestvalue = 0;
// setup code runs once:
void setup() {
pinMode(requestEnterPin, INPUT);
pinMode(openDoorPin, OUTPUT);
2024-05-22 11:49:17 +00:00
delay(2);
WiFi.config(local_IP, gateway, subnet, primaryDNS, secondaryDNS);
WiFi.begin(ssid);
delay(3);
server.on("/open", openDoor);
server.begin();
}
void openDoor() {
2024-05-22 11:49:17 +00:00
digitalWrite(openDoorPin, HIGH);
}
void closeDoor() {
analogWrite(openDoorPin, LOW);
}
bool askToOpen() {
requestvalue = analogRead(requestEnterPin);
if ( requestvalue > 100 ) {
return true;
} else {
return false;
}
}
// main code runs repeatedly:
void loop() {
if ( askToOpen() ) {
openDoor();
2024-05-22 11:49:17 +00:00
} else {
closeDoor();
}
delay(1);
2024-05-22 11:49:17 +00:00
//WiFi.status() != WL_CONNECTED
//WiFi.localIP()
}