Thursday, December 31, 2015

Standalone ESP8266/ESP-12, read GPIO with pull-up resistor.


This example set GPIO12 as input with pull-up resistor. Turn ON/OFF on-board LED according to GPIO12 input.

/*
 ESP8266 Read input from GPIO12, write to on-board LED
*/

int pin_Button = 12;  //GPIO12 

void setup() {

  pinMode(BUILTIN_LED, OUTPUT);
  pinMode(pin_Button, INPUT_PULLUP);
}

void loop() {

  if(digitalRead(pin_Button)){
    digitalWrite(BUILTIN_LED, LOW);   //LED ON
  }else{
    digitalWrite(BUILTIN_LED, HIGH);  //LED OFF
  }

}