I was wondering if instead of doing several digitalWrite commands to set individual output pin levels
on an Arduino (e.g. digitalWrite(D0, HIGH) - digitalWrite(D7, HIGH)) if there is a way to just write a
byte of data to set all output levels at once.
Also, is there a way to set all of the pinModes at once also... (like writing a value to a register for example)
thanks
Sure. You can find out what port name and bit numbers are used on your particular board and program them directly.
For example, an an Arduino UNO:
pinMode(8, INPUT) == DDRB &= ~_BV(0)
pinMode(8, OUTPUT) == DDRB |= _BV(0)
digitalWrite(8, HIGH) == PORTB |= _BV(0)
digitalWrite(8, LOW) == PORTB &= ~_BV(0)
x = digitalRead(8) == x = PINB & _BV(0) ? 1 : 0
Set pinmode of pins 7 through 0 as outputs in one shot:
DDRD = 0b11111111;
As all inputs:
DDRD = 0b00000000;
Bits 0...3 as input, 4...7 as outputs:
DDRD = 0 | _BV(4) | _BV(5) | _BV(6) | _BV(7);