Go Down

Topic: On one line (Read 1 time) previous topic - next topic

donde

I want to put this on one line.

pinMode(2, OUTPUT);
All the way through to pin 10. Can it be done?

Also, digitalWrite(2, LOW);
All the way through to pin 10. Same?

guix

#1
Oct 12, 2012, 07:05 am Last Edit: Oct 12, 2012, 07:07 am by guix Reason: 1
Using a for loop:
Code: [Select]

for ( byte i = 2; i <= 10; i++ )
{
 pinMode( i, OUTPUT );
 digitalWrite( i, LOW );
}


Well not really one line but almost :)

Nick Gammon

Modifying guix's suggestion:

Code: [Select]
for ( byte i = 2; i <= 10; i++ )  pinMode( i, OUTPUT );


One line. :P

Nick Gammon

And without spaces?

Code: [Select]

for(byte i=2;i<=10;i++)pinMode(i,OUTPUT);

donde

All right already! The big bad FOR shows it head again!
Thought I could do it with these things:  (   ),    [   ],    {   }
But, guess not.
Thanks all... :)

Go Up