Add geiger app

This commit is contained in:
Thammi 2013-09-04 01:52:32 +02:00
parent 329a153a2c
commit 2730c69f59
3 changed files with 63 additions and 3 deletions

View File

@ -16,11 +16,11 @@ static void init(void) {
}
static void run(void) {
uint16_t light = photons_measure();
uint8_t light = photons_measure();
pentatonic_all_led_set(light >> 3);
motor_set(biased_random(light) > 0x50 ? ON : OFF);
motor_set(biased_random(light) > 0x50);
led_set(RIGHT, biased_random(light) > 0x20);
led_set(LEFT, biased_random(light) > 0x20);

60
firmware/apps/geiger.c Normal file
View File

@ -0,0 +1,60 @@
#include <pentabug/app.h>
#include <pentabug/music.h>
#include <pentabug/photons.h>
#include <pentabug/hal.h>
inline uint16_t biased_random(uint8_t value) {
return value / 4 * (rand() & 7);
}
enum modes {
GEIGER,
TWITCH,
MAX_MODE,
};
static void init(void) {
photons_init();
}
static enum modes mode = 0;
static void run(void) {
uint8_t light = photons_measure();
if(button_clicked(RIGHT)) {
++mode;
if(mode == MAX_MODE) {
mode = 0;
}
}
if(button_clicked(LEFT)) {
if(mode == 0) {
mode = MAX_MODE;
}
--mode;
}
switch(mode) {
case GEIGER:
if(light / 16 * (rand() & 15) > 0x40) {
set_note(NOTE_C, 3);
} else {
stop_note();
}
wait_ms(20);
break;
case TWITCH:
set_note(500 + light, 0);
wait_ms(10);
break;
case MAX_MODE:
break;
}
}
REGISTER(run, init, NULL);

View File

@ -8,7 +8,7 @@
#include <pentabug/timer.h>
static volatile uint8_t ir_active = 0;
static int int_skip = 0;
static uint16_t int_skip = 0;
static volatile int16_t wait_time = 0;
static uint16_t button_count[2];