#define set1(R,b) R|=1<<b
#define set0(R,b) ~(R&=1<<b)
#define test(R,b) (R&(1<<b))
bool off = 1;
void setup() {
Serial.begin(9600);
DDRD |= 0b00000000;
DDRB |= 0b00000000;
PORTB |= 0b00111111;
PORTD |= 0b11100000;
set0(DDRB, 5);
set1(PORTB, 5);
}
void loop() {
if (test(PINB, 5) == 0 && off) {
for (int i = 4; i > -1; i--) {
if (test(PINB, i) == 0) {
Serial.print(0);
Serial.print(" ");
}
else if (test(PINB, i) != 0) {
Serial.print(1);
Serial.print(" ");
}
}
for (int i = 7; i > 4; i--) {
if (test(PIND, i) == 0) {
Serial.print(0);
Serial.print(" ");
}
else if (test(PIND, i) != 0) {
Serial.print(1);
Serial.print(" ");
}
}
Serial.println("");
off = false;
}
else if (test(PINB, 5) != 0 && !off) {
off = true;
}
}