close-circle
Close

NodeMCU Sktepch

A project log for Flashing Light Prize (5) IoT Pacing

Stress Shd Be More Stressful

Vije Miller 07/21/2017 at 02:410 Comments
// Flashing Light Prize (5) IoT Pacing
// Step Code
// VijeMiller
// NodeMCU ESP-12E 1.0
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
// WIFI Network Access
const char* ssid = "networkID";
const char* password = "networkpassword";
WiFiServer server(80);
// Buttons
const int left = D2;
const int right = D3;
// Buttons State
int lstate;
int rstate;
int state = 0;
int led = D0;
void setup() {
  pinMode(left, INPUT);
  pinMode(right, INPUT);
  pinMode(led, OUTPUT);
  Serial.begin(9600);
  while (WiFi.status() != WL_CONNECTED) {
    WiFi.begin(ssid, password);
    delay(5000);
  }
  Serial.println("Connected");
  digitalWrite(led, HIGH);
  server.begin();
}
void loop() {
  // Read Buttons
  lstate = digitalRead(left);
  rstate = digitalRead(right);
  // Declare Task
  HTTPClient http;
  int httpCode;
  if (lstate == HIGH && rstate == LOW) {
    // Prevent Excess
    if (state == 0) {
      Serial.println("L");
      // Load .php that writes to .txt
      http.begin("http://website.com/flp/flp.php?state=1");
      httpCode = http.GET();
      http.end();
      state = 1;
    } else {
      // Nothing
    }
  } else if (rstate == HIGH && lstate == LOW) {
    if (state == 1) {
      Serial.println("R");
      http.begin("http://website.com/flp/flp.php?state=0");
      httpCode = http.GET();
      http.end();
      state = 0;
    } else {
      // Nothing
    }
  } else if (lstate == HIGH && rstate == HIGH) {
    // Zilch
  } else if (lstate == LOW && rstate == LOW) {
    // Nope
  }
  delay(100);
}

Discussions