Use this forum to chat about hardware specific topics for the ESP8266 (peripherals, memory, clocks, JTAG, programming)

User avatar
By mbbackus
#24355 The button is definitely useful - just need to pull it up whenever you use it. Here's an example that controls the LED onboard the ESP8266. As a side effect, the LED attached to pin 16 (the LED next to the user button) also lights up whenever the button is pressed.

Code: Select allconst int buttonPin = 16;
const int ledPin = 1;

void setup() {
  pinMode(buttonPin, INPUT);
  pinMode(ledPin, OUTPUT);
}

void loop() {
  if (digitalRead(buttonPin) == HIGH)
  {
    digitalWrite(ledPin, HIGH);
  }
  else
  {
    digitalWrite(ledPin, LOW);
    pinMode(buttonPin, OUTPUT);
    digitalWrite(buttonPin, HIGH);
    pinMode(buttonPin, INPUT);
  }
}