for (int pinNumber = 2; pinNumber < 5; pinNumber++) {
pinMode(pinNumber, OUTPUT);
digitalWrite(pinNumber, LOW);
}
I'm very new to Arduino. Thanks in advance!
for (int pinNumber = 2; pinNumber < 5; pinNumber++) {
pinMode(pinNumber, OUTPUT);
digitalWrite(pinNumber, LOW);
}
I'm very new to Arduino. Thanks in advance!
It sets pins numbers 2 to 4 to OUTPUT and sets them LOW
so =2 is the smallest number, <5 is the highest number(4) and ++ is just one more (2+1 =3) 3+1=4
is that right?
Basically you are correct
Think of the for loop as a while loop if it makes things easier
int pinNumber = 2; //number of the first pin
while (pinNumber < 5) //ie 2, 3 and 4
{
pinMode(pinNumber, OUTPUT); //set the mode of the current pin
digitalWrite, pinNumber, LOW); //write LOW to the current pin
pinNumber = pinNumber +1; //increment the pin number
}
Thank you very much! This really helped.