pentabug/firmware/apps/buggy.c

39 lines
741 B
C
Raw Normal View History

#include <stdlib.h>
#include <pentabug/app.h>
#include <pentabug/hal.h>
#include <pentabug/photons.h>
#include <pentabug/pentatonic.h>
2013-09-03 22:49:52 +02:00
#include <pentabug/music.h>
2013-09-03 22:10:33 +02:00
inline uint16_t biased_random(uint8_t value) {
return value / 4 * (rand() & 7);
}
static void init(void) {
pentatonic_direction(ALL_OUT);
photons_init();
}
static void run(void) {
2013-09-04 01:52:32 +02:00
uint8_t light = photons_measure();
2013-09-03 20:14:30 +02:00
pentatonic_all_led_set(light >> 3);
2013-09-04 01:52:32 +02:00
motor_set(biased_random(light) > 0x50);
2013-09-03 22:10:33 +02:00
led_set(RIGHT, biased_random(light) > 0x20);
led_set(LEFT, biased_random(light) > 0x20);
2013-09-03 22:12:53 +02:00
if(biased_random(light) > 0x70) {
2013-09-03 22:10:33 +02:00
uint16_t tone = (biased_random(light) * 2) + 500;
set_note(tone, 0);
} else {
stop_note();
}
2013-09-03 21:25:07 +02:00
2013-09-03 22:10:33 +02:00
wait_ms(200);
}
REGISTER(run, init, NULL);