Hi!
How can I set pinMode as OUTPUT from 2 to 11 digital pin in one line?
Hi!
How can I set pinMode as OUTPUT from 2 to 11 digital pin in one line?
The best way to do it is to define the pins in an array, then use a for loop to iterate over the array and call pinMode() from inside that for loop.
You can learn more from these reference pages:
After reading those, give it a try and if you get stuck post the code from your attempt and a detailed description of the problem you had here and we'll help you out.
Dont try and put too much in one line it makes the code hard to read , debug and serves no purpose !
If setting all from 2to 11 as output a simple method is ...
Pseudo code ....
//configure outputs:
For ( int I=2; I=11; I++)
{
pinMode (I , OUTPUT);
}
//*******
It’s better to name each output , then set them so you know what each does :
int Motor= 2;
int Lamp =3;
pinMode ( Motor, OUTPUT);
pinMode ( Lamp, OUTPUT);
And so on ... much easier to debug/modify later on if you use logical names
hammy:
Pseudo code ....
//configure outputs:
For ( int I=2; I=11; I++)
{
pinMode (I , OUTPUT);
}
//*******
In one line, as the OP requested:
for (int pin=2; pin <= 11; pin++) pinMode(pin, OUTPUT);
johnwasser:
In one line, as the OP requested:for (int pin=2; pin <= 11; pin++) pinMode(pin, OUTPUT);
Thank You!
Come on, guys! You all KNOW the code will run faster and take up less space if it's written on one line, instead of multiple lines. And, of course, you can save a ton of space by naming all your variables and functions using all lower-case characters, rather than those big upper-case ones! ![]()
This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.