I just make four pins to active HIGH
I simplified my code as below
//my script
void setup() {
}
void loop() {
digitalWrite(2,HIGH);
digitalWrite(5,HIGH);
digitalWrite(6,HIGH);
digitalWrite( 12,HIGH);
}
but I want to use for loop to simply it, and try to modified as below
byte digitPins[] = {2, 5, 6, 12};
void setup() {
}
void loop() {
for (int j=0;j<4;j++)
digitalWrite(digitPins[j],HIGH);
}
<-- although it is no grammatical error on coding, but behavior is not my desire.
Can some one point me or give some advice for me? thx...
system
2
but behavior is not my desire.
You forgot to pinMode the pins as outputs.
What is your desire, and what's the actual behaviour?
thank you for prompt reply.
I also modified my code. does it workable?
byte digitPins[] = {2, 5, A1, A2};
void setup() {
for (int j=0;sizeof(digitPins);j++)
pinMode(digitPins[j], OUTPUT);
}
void loop() {
for (int j=0;sizeof(digitPins);j++)
digitalWrite(digitPins[j],HIGH);
}
system
4
cools0607:
does it workable?
Beats me 
Does it compile?
If so, is its behaviour to your liking?
system
5
for (int j=0;sizeof(digitPins);j++)
Oops