hi i used all the pins in the nodemcu for my project. from D0-D8, when i upload the program it is succesfull but when i run the program the program crashes, because i used the default built in led as an output of my LED.
const int Green = 2; // GPIO00 = D4 Green
const int Orange = 13; // GPIO13 = D7 Orange
const int Red = 15; // GPIO15 = D8 Red
const int SW_One = 16; // GPIO16 = D0 SW_One
const int SW_Two = 5; // GPIO05 = D1 SW_Two
const int SW_Three = 4; // GPIO04 = D2 SW_Three
const int SW_Four = 14; // GPIO14 = D5 SW_Four
const int SW_Five = 12; // GPIO12 = D6 SW_Five
void setup() {
pinMode(LED_BUILTIN, OUTPUT); // Initialize the LED_BUILTIN pin as an output
pinMode(Green, OUTPUT); // D3 (GREEN)
pinMode(Orange, OUTPUT); // D7 (ORANGE)
pinMode(Red, OUTPUT); // D8 (RED)
pinMode(SW_One, INPUT); // D0 (SW_One)
pinMode(SW_Two, INPUT); // D1 (SW_Two)
pinMode(SW_Three, INPUT); // D2 (SW_Three)
pinMode(SW_Four, INPUT); // D5 (SW_Four)
pinMode(SW_Five, INPUT); // D6 (SW_Five)
}
// the loop function runs over and over again forever
void loop() {
//digitalWrite(LED_BUILTIN, LOW); // Turn the LED on (Note that LOW is the voltage level
//delay(1000); // Wait for a second
//digitalWrite(LED_BUILTIN, HIGH); // Turn the LED off by making the voltage HIGH
//delay(2000); // Wait for two seconds (to demonstrate the active low LED)
read_SW_One(); //
read_SW_Two();
read_SW_Three();
read_SW_Four();
read_SW_Five();
}
void read_SW_One(void)
{
if (digitalRead(SW_One)){
digitalWrite(Green, HIGH);
digitalWrite(Orange, LOW);
digitalWrite(Red, LOW);
}
}
void read_SW_Two(void)
{
if (digitalRead(SW_Two)){
digitalWrite(Green, LOW);
digitalWrite(Orange, HIGH);
digitalWrite(Red, LOW);
}
}
void read_SW_Three(void)
{
if (digitalRead(SW_Three)){
digitalWrite(Green, LOW);
digitalWrite(Orange, LOW);
digitalWrite(Red, HIGH);
}
}
void read_SW_Four(void)
{
if (digitalRead(SW_Four)){
digitalWrite(Green, HIGH);
digitalWrite(Orange, HIGH);
digitalWrite(Red, LOW);
}
}
void read_SW_Five(void)
{
if (digitalRead(SW_Five)){
digitalWrite(Green, HIGH);
digitalWrite(Orange, LOW);
digitalWrite(Red, HIGH);
}
}