#include <htc.h>
#include <stdlib.h>
#include "picinit.h"
+#include "unused.h"
#include "buttons.h"
#include "rgb.h"
-#include "unused.h"
+#include "timer.h"
-#define STEP_SIZE 32 /* ms */
#define reset_steps() do { incolor_steps = 1; fade_steps = 0; } \
while (0)
#define rand_u8() (rand() & 0xff)
#define leds_set(r,g,b,w) rgb_set((r).value >> 7, \
(g).value >> 7, \
(b).value >> 7, \
- (w).value >> 7)
+ 0)
typedef struct {
int value;
const static int range_fade_steps[4] = { 1, 1, 1, 1 };
#endif
+#define dbgpin_init() \
+do { \
+ /* Set RA2 as output low */ \
+ PORTA &= ~0x04; \
+ TRISA &= ~0x04; \
+} while (0)
+
+#define dbgpin_high() PORTA |= 0x04;
+#define dbgpin_low() PORTA &= ~0x04;
+
int main(void)
{
led_t red = INIT_LED;
unused_init();
buttons_init();
rgb_init();
+ timer_init();
+ dbgpin_init();
reset_steps();
if (buttons_on())
rgb_on();
+ dbgpin_high();
while (1) {
unsigned char buttons = buttons_read();
wht.increment = (neww - wht.value) / fade_steps;
wht.remainder = neww - (wht.value + wht.increment * fade_steps);
}
- __delay_ms(STEP_SIZE); /* step should be start to start... */
+ dbgpin_low();
+ timer_owait(); /* wait 32 ms since last return from last call() */
+ dbgpin_high();
} else {
rgb_off();
+ dbgpin_low();
buttons_sleep();
+ dbgpin_high();
reset_steps();
rgb_on();
red.value = 0;