avr/tron-bag/main.c

53 lines
989 B
C

#include <avr/interrupt.h>
#include <avr/sleep.h>
#include <dio.h>
#define FPS 10
#define FPS_MS 1000 / FPS
#define MULT 5
typedef struct {
uint8_t value;
int8_t inc;
} counter_t;
void counter_update(counter_t *self) {
int16_t value = self->value;
value += self->inc;
if (value >= 255) {
self->value = 255;
self->inc = -1;
} else if (value <= 0) {
self->value = 0;
self->inc = 1;
} else {
self->value = value;
}
}
int main(void) {
DDRB = 0xff;
PORTB = 0;
GTCCR = 0;
TCCR0A = _BV(COM0A1) | _BV(COM0B1) | _BV(WGM01) | _BV(WGM00);
TCCR0B = _BV(CS00);
counter_t red = (counter_t){ .value = 128, .inc = 1 };
counter_t blue = (counter_t){ .value = 0, .inc = 1 };
while(1) {
OCR0A = red.value;
OCR0B = blue.value;
_delay_ms(10);
counter_update(&red);
counter_update(&blue);
}
return 0;
}