#include "logging.h"
-static unsigned char pwm = 1;
+#define N_STEPS 5
+static unsigned char steps[] = { 60, 85, 121, 171, 242 };
+static unsigned char intensity = 0;
static void timer_init()
{
// TCCR1 = _BV(CS11) | _BV(CS13); // clk/512 = 2 kHz
GTCCR = _BV(COM1B1) | _BV(PWM1B);
OCR1C = 255;
+ OCR1B = 0;
+}
+
+static void set_pwm(unsigned char pwm)
+{
OCR1B = pwm;
}
PORTB &= ~_BV(PB2);
}
+static unsigned char status_led_is_on()
+{
+ return PORTB & _BV(PB2) ? 1 : 0;
+}
+
static void buttons_init()
{
DDRB &= ~(_BV(PB0) | _BV(PB1)); // set as input
static void button_one_pressed()
{
- if (pwm > 1) {
- pwm >>= 1;
- OCR1B = pwm;
+ if (intensity > 0) {
+ set_pwm(steps[--intensity]);
} else {
power_down();
}
static void button_two_pressed()
{
- if (pwm < 0x80) {
- pwm <<= 1;
- OCR1B = pwm;
+ if (intensity < N_STEPS-1) {
+ set_pwm(steps[++intensity]);
}
}
button_state = newstate;
}
+static unsigned char blink_on_time, blink_off_time, n_blinks;
+static unsigned char blink_counter;
+
+static void timer_blink()
+{
+ if (blink_counter) {
+ blink_counter--;
+ } else if (status_led_is_on()) {
+ status_led_off();
+ blink_counter = blink_off_time;
+ } else if (n_blinks) {
+ --n_blinks;
+ status_led_on();
+ blink_counter = blink_on_time;
+ } else {
+ n_blinks = intensity + 1;
+ blink_on_time = 0;
+ blink_off_time = 2;
+ blink_counter = 10;
+ }
+}
+
int main()
{
log_init();
if (wdt_timer_fired) {
wdt_timer_fired = 0;
timer_check_buttons();
+ timer_blink();
}
}
}