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
  }

}


1 comment:

  1. Hi
    Is there some code using Arduino IDE to read and get the status of any pin on the V1 ESP8266? for example:
    if (gpio.read (2) == 0) then
    or something similar that works in arduino IDE

    ReplyDelete