void gol_play (int iterations, int delay) { int i; for (i = 0; i < iterations; i++) { LED_PORT ^= LED_GREEN; gol_nextgen(); if (gol_count_changes() == 0) return; tmp2cube(); delay_ms(delay); //led_red(1); } }
// Take input from a computer and load it onto the cube buffer void rs232() { char tempval; int x = 0; int y = 0; int escape = 0; while (current_mode == MODE_BINARY) { // Switch state on red LED for debugging // Should switch state every time the code // is waiting for a byte to be received. debug_blink(LED_RED); // Wait until a byte has been received while(!HasChars()); // Load the received byte from rs232 into a buffer. receive_char(&tempval); // Uncommet this to echo data back to the computer // for debugging purposes. //SendChar(tempval); // Every time the cube receives a 0xff byte, // it goes into sync escape mode. // if a 0x00 byte is then received, the x and y counters // are reset to 0. This way the x and y counters are // always the same on the computer and in the cube. // To send an 0xff byte, you have to send it twice! // Go into sync escape mode if (tempval == 0xff) { // Wait for the next byte while(!HasChars()); // Get the next byte receive_char(&tempval); // Sync signal is received. // Reset x and y counters to 0. if (tempval == 0x00) { x = 0; y = 0; escape = 1; } // if no 0x00 byte is received, proceed with // the byte we just received. } if (escape == 0) { // Load data into the current position in the buffer fb[x][y] = tempval; // Check if we have reached the limits of the buffer array. if (y == 7) { if (x == 7) { // All data is loaded. Reset both counters y = 0; x = 0; // Copy the data onto the cube. tmp2cube(); } else { // A layer is loaded, reset y and increment x. x++; y = 0; } } else { // We are in the middle of loading a layer. increment y. y++; } } else { escape = 0; } } }