The page https://docs.arduino.cc/learn/programming/bit-math/ gives below example for setting pins using registers, supposedly much faster than using a loop and pinMode and digitalWrite. Is there an easy way to print each bit for these ports in loop()?? Thanks for any help. AA
void setup() {
DDRD = B11111110; // digital pins 7,6,5,4,3,2,1,0
PORTD &= B00000011; // turns off 2..7, but leaves pins 0 and 1 alone
DDRB = B00111111; // digital pins -,-,13,12,11,10,9,8
PORTB = B00111000; // turns on 13,12,11; turns off 10,9,8
}
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
DDRD = DDRD | B11111100;
PORTD = B10100000;
}
void loop() {
// put your main code here, to run repeatedly:
Serial.println("Binary");
Serial.println(PORTD,BIN);
Serial.println();
Serial.println("Decimal");
Serial.println(PORTD,DEC);
Serial.println();
delay(5000);
PORTD += 4;
}