uint8_t led = 1;
uint8_t knop = false;
void setup() {
DDRB = 0b00001100;
PORTB |= (1<<1);
DDRD = 0b11111111;
}
void loop() {
static uint8_t led = 1; // lopende 1
static uint8_t richting = 1; // 1 = links, 0 = rechts
static uint8_t vorig = 1;
uint8_t huidig = PINB & (1 << PB0);
// detecteer knopdruk (falling edge)
if (vorig && !huidig) {
richting = !richting; // toggle richting
}
vorig = huidig;
PORTD = led;
delay(300);
uint8_t huidig = PINB & (1 << PB0);
if (richting) {
led <<= 1;
if (led == 0) led = 1;
} else {
led >>= 1;
if (led == 0) led = 0x80;
}
}
/*
PORTD &= ~(1 << 0); // PC7 laag
PORTD |= (1 << 1); // PC0 hoog
delay(500);
PORTD &= ~(1 << 1); // PC7 laag
PORTD |= (1 << 2); // PC0 hoog
delay(500);
PORTD &= ~(1 << 2); // PC7 laag
PORTD |= (1 << 3); // PC0 hoog
delay(500);
PORTD &= ~(1 << 3); // PC7 laag
PORTD |= (1 << 4); // PC0 hoog
delay(500);
PORTD &= ~(1 << 4); // PC7 laag
PORTD |= (1 << 5); // PC0 hoog
delay(500);
PORTD &= ~(1 << 5); // PC7 laag
PORTD |= (1 << 6); // PC0 hoog
delay(500);
// toestand 2: PC7 = LOW, PC0 = HIGH
PORTD &= ~(1 << 6); // PC7 laag
PORTD |= (1 << 7); // PC0 hoog
delay(500);
PORTD &= ~(1 << 7); // PC7 laag
PORTD |= (1 << 0); // PC0 hoog
delay(500);
}
*/