/* * Code to controll an 8x8x8 ledcube using avr * http://www.instructables.com/id/Led-Cube-8x8x8/ * See lisence.txt for lisence. */ #include "main.h" #include "effect.h" #include "launch_effect.h" #include "draw.h" // Main loop // the AVR enters this function at boot time int main (void) { // This function initiates IO ports, timers, interrupts and // serial communications ioinit(); // This variable specifies which layer is currently being drawn by the // cube interrupt routine. We assign a value to it to make sure it's not >7. current_layer = 1; int i; // Boot wait // This function serves 3 purposes // 1) We delay starting up any interrupts, as drawing the cube causes a lot // noise that can confuse the ISP programmer. // 2) Listen for button press. One button means go into rs232 mode, // The other means go into autonomous mode and start doing stuff. // 3) Random seed. The bootwait function counts forever from 0 to 255. // Whenever you press the button, this counter stops, and the number it // stopped at is used as a random seed. This ensures true randomness at // every boot. Without this (or some similar process) the cube would // produce the same "random" sequence every time i = bootwait(); // Enable interrupts // This starts the routine that draws the cube content sei(); // Result for bootwait() is 2: // Go to rs232 mode. this function loops forever. if (i == 2) { rs232(); } // Result of bootwait() is something other than 2: // Do awesome effects. Loop forever. while (1) { // Show the effects in a predefined order for (i=0; i> 8; UBRRL = MYUBRR; // UCSRC - USART control register // bit 7-6 sync/ascyn 00 = async, 01 = sync // bit 5-4 parity 00 = disabled // bit 3 stop bits 0 = 1 bit 1 = 2 bits // bit 2-1 frame length 11 = 8 // bit 0 clock polarity = 0 UCSRC = 0b10000110; // Enable RS232, tx and rx UCSRB = (1<