/* -------------------------------------------------------------------- Ultraluminous version 5 main control loop. Author: Brian Neltner, Dan Taub Copyright: 2008 Dependencies: benc.c avr/io.h avr/interrupt.h Details: This is the top level function to control the ultraluminous illuminator. Some example default code for light fading is included. Structure: benc.c provides byte encoded outputs. brightnesses are controlled through RED, ORANGE, AMBER, GREEN, CYAN, BLUE, and RBLUE, are double buffered, written with benc_update(), and load to the brightness module at the start of the next loop to avoid glitches. benc.c requires a timer interrupt (TIMER3_COMPA_vect) to function. This should be the higest priority interrupt in order to avoid glitches. Unfortunately, because this is a one interrupt architecture, that means serial communication will have to be done via polling in the main loop. Dan is going to implement RF with the ATAVRRZ502 Evaluation Board. It will require timer 1. -------------------------------------------------------------------*/ #define F_CPU 8000000UL // in Hz #define benc_freq 300UL // byte encoding total frequency in Hz #define delay_time 5000UL //#define light_location 4 #include #include #include "benc.c" #include #include "com.h" #include "com.c" int main(void); void init_uart(void); void delay(long); uint8_t mode; uint8_t stop_fade; uint8_t freeze_fade; int main(void) { uint8_t light; uint8_t newlight; uint8_t light_location; uint8_t received_byte; uint8_t first_digit, second_digit, third_digit; uint8_t digit_location; uint8_t j; init_timer(); init_uart(); mode = 0; digit_location = 0; first_digit = 0; second_digit = 0; third_digit = 0; stop_fade = 0; freeze_fade = 0; light_location = 0; if(mode==0) { light=(uint8_t)(rand() % 7); while((BENC[light]<0xFF) && (stop_fade==0)) { if(freeze_fade==0) { BENC[light]++; update_benc(); } delay(delay_time); } } while(1) { switch(mode) { case 0: // This randomly picks a color and switches to it each cycle. BENC[light]=0xFF; while((newlight=(uint8_t)(rand() % 7))==light); while((BENC[newlight]<0xFF) && (stop_fade==0)) { if(freeze_fade==0){ BENC[newlight]++; BENC[light]--; update_benc(); } delay(delay_time); } BENC[light]=0x00; BENC[newlight]=0xFF; light=newlight; break; case 1: while( !(UCSR1A & (1<