toggle button
This commit is contained in:
parent
327b1eb33f
commit
90c8d9b1d6
10
.vscode/extensions.json
vendored
Normal file
10
.vscode/extensions.json
vendored
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
// See http://go.microsoft.com/fwlink/?LinkId=827846
|
||||||
|
// for the documentation about the extensions.json format
|
||||||
|
"recommendations": [
|
||||||
|
"platformio.platformio-ide"
|
||||||
|
],
|
||||||
|
"unwantedRecommendations": [
|
||||||
|
"ms-vscode.cpptools-extension-pack"
|
||||||
|
]
|
||||||
|
}
|
41
src/main.cpp
41
src/main.cpp
@ -6,9 +6,11 @@
|
|||||||
|
|
||||||
#ifndef APSSID
|
#ifndef APSSID
|
||||||
#define APSSID "ESPap"
|
#define APSSID "ESPap"
|
||||||
#define APPSK "thereisnospoon"
|
#define APPSK "thereisnospoon"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define BUTTON D2
|
||||||
|
|
||||||
/* Set these to your desired credentials. */
|
/* Set these to your desired credentials. */
|
||||||
const char *APssid = APSSID;
|
const char *APssid = APSSID;
|
||||||
const char *APpassword = APPSK;
|
const char *APpassword = APPSK;
|
||||||
@ -21,7 +23,8 @@ WiFiClient wifiClient;
|
|||||||
|
|
||||||
String HOST_ADDRESS = "192.168.0.47";
|
String HOST_ADDRESS = "192.168.0.47";
|
||||||
|
|
||||||
String make_toggle_request(){
|
String make_toggle_request()
|
||||||
|
{
|
||||||
HTTPClient http;
|
HTTPClient http;
|
||||||
String ADCData, station, getData, request;
|
String ADCData, station, getData, request;
|
||||||
|
|
||||||
@ -36,18 +39,22 @@ String make_toggle_request(){
|
|||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
void handleRoot() {
|
void handleRoot()
|
||||||
make_toggle_request();
|
{
|
||||||
web_server.send(200, "text/html", "<h1>Deu bom!</h1>");
|
String response = make_toggle_request();
|
||||||
|
web_server.send(200, "text/html", response);
|
||||||
}
|
}
|
||||||
|
|
||||||
void handleSetHost() {
|
void handleSetHost()
|
||||||
|
{
|
||||||
String host = web_server.arg("host");
|
String host = web_server.arg("host");
|
||||||
Serial.println("Setting host to: " + host);
|
Serial.println("Setting host to: " + host);
|
||||||
HOST_ADDRESS = host;
|
HOST_ADDRESS = host;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup() {
|
void setup()
|
||||||
|
{
|
||||||
|
pinMode(BUTTON, INPUT_PULLUP);
|
||||||
delay(1000);
|
delay(1000);
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
Serial.println("Init");
|
Serial.println("Init");
|
||||||
@ -57,7 +64,8 @@ void setup() {
|
|||||||
// WiFi.mode(WIFI_AP_STA);
|
// WiFi.mode(WIFI_AP_STA);
|
||||||
// WiFi.softAP(APssid, APpassword);
|
// WiFi.softAP(APssid, APpassword);
|
||||||
WiFi.begin(ssid, password);
|
WiFi.begin(ssid, password);
|
||||||
while (WiFi.status() != WL_CONNECTED) {
|
while (WiFi.status() != WL_CONNECTED)
|
||||||
|
{
|
||||||
Serial.print('.');
|
Serial.print('.');
|
||||||
delay(1000);
|
delay(1000);
|
||||||
}
|
}
|
||||||
@ -71,7 +79,22 @@ void setup() {
|
|||||||
Serial.println("HTTP server started");
|
Serial.println("HTTP server started");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void loop()
|
||||||
|
{
|
||||||
|
if(digitalRead(BUTTON) == LOW) {
|
||||||
|
//digitalWrite(LED_BUILTIN, HIGH);
|
||||||
|
//int v = digitalRead(BUTTON);
|
||||||
|
//Serial.print("READ: ");
|
||||||
|
//Serial.println(v);
|
||||||
|
// Wait for the button to be released
|
||||||
|
//while(digitalRead(BUTTON) == LOW) {
|
||||||
|
// delay(100);
|
||||||
|
//}
|
||||||
|
//digitalWrite(LED_BUILTIN, LOW);
|
||||||
|
//Serial.println("BOO");
|
||||||
|
make_toggle_request();
|
||||||
|
delay(500);
|
||||||
|
}
|
||||||
|
|
||||||
void loop() {
|
|
||||||
web_server.handleClient();
|
web_server.handleClient();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user