Go Down

Topic: Easier digital output (Read 525 times) previous topic - next topic

N314

Is there a quicker way I can control several digital pins without having to use "digitalWrite" every time?

WizenedEE

If they're all on the same port, you can use Port Manipulation, or you could put all your pin numbers in an array and loop through the array:
Code: [Select]

byte pin_numbers[] = {3, 4, 6, 7, 8, 9}

for (byte i=0;i<6;i++) {
  digitalWrite(i, HIGH);
}


However, that is slower to execute. Then, there is always copy+paste :)

Grumpy_Mike

Note here that slower is a relative term and in practice you will not see any difference. This is the way to do it.

Nick Gammon


Is there a quicker way I can control several digital pins without having to use "digitalWrite" every time?


Why do you want to?
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Go Up