mrnams
Junior Member level 1
Once we give low input to pin 16 of NodeMCU ESP8266, it remains low, see my code below which is not able to switch off led because of this issue, can't we use pin 16 as general purpose input?
See my complete code
[moderator action: removed link to external file server]
See my complete code
Code:
#include <Arduino.h>
#define ENABLE_DEBUG
#ifdef ENABLE_DEBUG
#define DEBUG_ESP_PORT Serial
#define NODEBUG_WEBSOCKETS
#define NDEBUG
#endif
enum LedStatus
{
LedOff = 0,
LedOn = 1
};
enum LedStatus curentLedStatus = LedOff;
#define BAUD_RATE 9600
// Pins of push buttons and led
#define pinPButtonLedOn 16
#define pinPButtonLedOff 5
#define pinLed 4
void setup()
{
Serial.begin(BAUD_RATE);
// put your setup code here, to run once:
pinMode(pinPButtonLedOn, INPUT_PULLUP); // set arduino pin to input pull-up mode
pinMode(pinPButtonLedOff, INPUT_PULLUP); // set arduino pin to input pull-up mode
pinMode(pinLed, OUTPUT); // set arduino pin to output mode
}
void loop()
{
// put your main code here, to run repeatedly:
Serial.printf("\n \n \n On button state :");
Serial.print(digitalRead(pinPButtonLedOn));
Serial.printf("\n \n \n Off button state :");
Serial.print(digitalRead(pinPButtonLedOff));
if (digitalRead(pinPButtonLedOn) == LOW && curentLedStatus == LedOff)
{
digitalWrite(pinLed, HIGH);
curentLedStatus = LedOn;
Serial.printf("\n \n \n Led turned On by Push Button");
}
if (digitalRead(pinPButtonLedOff) == LOW && curentLedStatus == LedOn)
{
digitalWrite(pinLed, LOW);
curentLedStatus = LedOff;
Serial.printf("\n \n \n Led turned Off by Push Button");
}
}
Last edited by a moderator: