-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProjeto-II.cpp
80 lines (55 loc) · 1.66 KB
/
Projeto-II.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
//config Rede
const char* ssid = "PROF.RAFAEL"; //Roteador
const char* password = "";
IPAddress ip(192,168,1,123); //ip do dispositivo
IPAddress gateway(192,168,1,1); // gateway
IPAddress subnet(255,255,255,0); //mascara
ESP8266WebServer server(80);
String page;
//porta digital
const int sensor = 4;
unsigned long evento = 0;
void setup() {
Serial.begin(9600);
//habilitar porta
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
WiFi.config(ip, gateway, subnet);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected.");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
server.begin();
server.on("/", [](){
page = "<!DOCTYPE html> \
<html> \
<head> <meta http-equiv='refresh' content='0' </head> \
<body> \
<h1>Sensor to Node MCU Web Server</h1><h3>Data:</h3> <h4> "+ "saida"+ " </h4> \
</body>\
</html>";
server.send(200, "text/html", page);
});
}
void loop(){
int output = digitalRead(sensor);
if (output == HIGH){
if(millis() - evento > 25){
Serial.println("Reconheci o som");
Serial.println(millis());
Serial.println(evento);
Serial.println(millis() - evento);
}
evento = millis();
}
server.handleClient();
}