Sorry for no-clear topic.
Using a nodemcu + Arduino IDE.
Pins are defined as follow:
#define D0 16
#define D1 5
#define D2 4
#define D3 0
#define D4 2
#define D5 14
#define D6 12
#define D7 13
Basically I would set on the leds from D0 to D4.
This is my code in loop section but it is ON only the D3 (!) pin.
for (int k=0; k<5; k++) {
String pin_string = "D"+k;
int pin = pin_string.toInt();
digitalWrite(pin,HIGH);
delay(100);
digitalWrite(pin,LOW);
delay(100);
}
Thank you very much.
wg0z
2
not the best approach. try this:
const unsigned char logical_pin_nums_0_7 ={ 16, 5, 4, 0, 2, 14 12, 13 };
for (int k=0; k<5; k++) {
digitalWrite(logical_pin_nums_0_7[k],HIGH);
delay(100);
digitalWrite(logical_pin_nums_0_7[k],LOW);
delay(100);
}
wg0z:
not the best approach. try this:
const unsigned char logical_pin_nums_0_7 ={ 16, 5, 4, 0, 2, 14 12, 13 };
for (int k=0; k<5; k++) {
digitalWrite(logical_pin_nums_0_7[k],HIGH);
delay(100);
digitalWrite(logical_pin_nums_0_7[k],LOW);
delay(100);
}
I would argue that this isn't the best either, since you define 8 pins in the array, but only cycle through 5. What am I missing?
system
4
int pin = pin_string.toInt();
"D0" is NOT an int.
Pin names are lost when the compiler converts everything to addresses, so this approach will never work.
Arrays ARE the way to go.