-->
Page 2 of 3

Re: NodeMCU - running arduino - User Button

PostPosted: Thu Jun 25, 2015 11:53 am
by martinayotte
Maybe the board itself has a pullup ? because otherwise, this switch will be useless ...

Re: NodeMCU - running arduino - User Button

PostPosted: Thu Jun 25, 2015 1:51 pm
by Iisfaq
Seems a bit useless to me at the moment.

Chris

Re: NodeMCU - running arduino - User Button

PostPosted: Sun Jul 26, 2015 9:04 pm
by aardvarko
I was having trouble with this too. Driving the pin high in OUTPUT mode for a moment seems to fix it.

e.g.,

Code: Select all  if (digitalRead(16)==0) {

    // do stuff...

    pinMode(16,OUTPUT);
    digitalWrite(16,HIGH);
    delay(1);
    pinMode(16,INPUT);


Re: NodeMCU - running arduino - User Button

PostPosted: Mon Jul 27, 2015 1:56 am
by mbbackus
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);
  }
}