/* All Default Animations. This sketch allows users to test their Rave Shades with some basic animations. http://www.instructables.com/id/Rave-Shades-The-Self-Assembly-LED-Glasses-Kit/ created 12 Apr 2013 by Frederick T. Ford This example code is in the public domain. */ #include //letter shapes #define A {{0,1,1,1,1},{1,0,1,0,0},{1,0,1,0,0},{0,1,1,1,1},{0,0,0,0,0}} #define B {{1,1,1,1,1},{1,0,1,0,1},{1,0,1,0,1},{0,1,0,1,0},{0,0,0,0,0}} #define C {{0,1,1,1,0},{1,0,0,0,1},{1,0,0,0,1},{0,0,0,0,0},{0,0,0,0,0}} #define D {{1,1,1,1,1},{1,0,0,0,1},{1,0,0,0,1},{0,1,1,1,0},{0,0,0,0,0}} #define E {{1,1,1,1,1},{1,0,1,0,1},{1,0,1,0,1},{1,0,1,0,1},{0,0,0,0,0}} #define F {{1,1,1,1,1},{1,0,1,0,0},{1,0,1,0,0},{1,0,0,0,0},{0,0,0,0,0}} #define G {{0,1,1,1,0},{1,0,0,0,1},{1,0,1,0,1},{1,0,1,1,1},{0,0,0,0,0}} #define H {{1,1,1,1,1},{0,0,1,0,0},{0,0,1,0,0},{1,1,1,1,1},{0,0,0,0,0}} #define I {{1,0,0,0,1},{1,1,1,1,1},{1,0,0,0,1},{0,0,0,0,0},{0,0,0,0,0}} #define J {{1,0,0,1,0},{1,0,0,0,1},{1,1,1,1,0},{1,0,0,0,0},{1,0,0,0,0}} #define K {{1,1,1,1,1},{0,1,1,1,0},{0,1,0,1,0},{1,0,0,0,1},{0,0,0,0,0}} #define L {{1,1,1,1,1},{0,0,0,0,1},{0,0,0,0,1},{0,0,0,0,0},{0,0,0,0,0}} #define M {{1,1,1,1,1},{0,1,0,0,0},{0,0,1,0,0},{0,1,0,0,0},{1,1,1,1,1}} #define N {{1,1,1,1,1},{0,1,0,0,0},{0,0,1,0,0},{0,0,0,1,0},{1,1,1,1,1}} #define O {{0,1,1,1,0},{1,0,0,0,1},{1,0,0,0,1},{0,1,1,1,0},{0,0,0,0,0}} #define P {{1,1,1,1,1},{1,0,1,0,0},{1,0,1,0,0},{0,1,0,0,0},{0,0,0,0,0}} #define Q {{0,1,1,1,0},{1,0,0,0,1},{1,0,1,0,1},{0,1,1,1,0},{0,0,0,0,1}} #define R {{1,1,1,1,1},{1,0,1,0,0},{1,0,1,1,0},{0,1,0,0,1},{0,0,0,0,0}} #define S {{0,1,0,0,1},{1,0,1,0,0},{1,0,0,1,0},{0,0,0,0,0},{0,0,0,0,0}} #define T {{1,0,0,0,0},{1,1,1,1,1},{1,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0}} #define U {{1,1,1,1,0},{0,0,0,0,1},{0,0,0,0,1},{1,1,1,1,0},{0,0,0,0,0}} #define V {{1,1,0,0,0},{0,0,1,1,0},{0,0,0,1,1},{0,0,1,1,0},{1,1,0,0,0}} #define W {{1,1,1,1,1},{0,0,0,1,0},{0,0,1,0,0},{0,0,0,1,0},{1,1,1,1,1}} #define X {{1,0,0,0,1},{0,1,0,1,0},{0,0,1,0,0},{0,1,0,1,0},{1,0,0,0,1}} #define Y {{1,0,0,0,0},{0,1,0,0,0},{0,0,1,1,1},{0,1,0,0,0},{1,0,0,0,0}} #define Z {{1,0,0,0,1},{1,0,0,1,1},{1,0,1,0,1},{1,1,0,0,1},{1,0,0,0,1}} #define SPACE{{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0}} unsigned char scroll_speed = 8; int DataPin = 11; //shift input int LatchPin = 10; //rstclk on shift int ClockPin = 13; //srclk on shift unsigned char row = 128; int i, x, y, z; int temp_cell = 0; unsigned char current_display [][8][3] = { {{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0}}}; unsigned char text_buffer [][8][3] = { {{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0}}}; // ###################################### Animation definitions go here !!! ########################################################################### unsigned char light [][8][3] PROGMEM = { {{63,255,252},{127,255,254},{255,255,255},{255,231,255},{255,231,255},{127,195,254},{127,129,254},{30,0,120}}, {{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0}}}; unsigned char arrowscont [][8][3] PROGMEM = { {{10,36,80},{17,24,136},{32,129,4},{68,66,34},{138,36,81},{17,0,136},{32,129,4},{4,0,32}}, {{17,24,136},{32,129,4},{68,66,34},{138,36,81},{17,0,136},{32,129,4},{68,0,34},{10,0,80}}, {{32,129,4},{68,66,34},{138,36,81},{17,0,136},{32,129,4},{68,66,34},{10,0,80},{16,0,8}}, {{4,0,32},{10,0,80},{17,0,136},{32,129,4},{68,66,34},{10,0,80},{17,0,136},{0,0,0}}}; unsigned char arrows [][8][3] PROGMEM = { {{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0}}, {{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{4,0,32}}, {{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{4,0,32},{10,0,80}}, {{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{4,0,32},{10,0,80},{16,0,8}}, {{0,0,0},{0,0,0},{0,0,0},{0,0,0},{4,0,32},{10,0,80},{17,0,136},{0,0,0}}, {{0,0,0},{0,0,0},{0,0,0},{4,0,32},{10,0,80},{17,0,136},{32,129,4},{4,0,32}}, {{0,0,0},{0,0,0},{4,0,32},{10,0,80},{17,0,136},{32,129,4},{68,0,34},{10,0,80}}, {{0,0,0},{4,0,32},{10,0,80},{17,0,136},{32,129,4},{68,66,34},{10,0,80},{16,0,8}}, {{4,0,32},{10,0,80},{17,0,136},{32,129,4},{68,66,34},{10,0,80},{17,0,136},{0,0,0}}, {{10,0,80},{17,0,136},{32,129,4},{68,66,34},{138,36,81},{17,0,136},{32,129,4},{4,0,32}}, {{17,0,136},{32,129,4},{68,66,34},{138,36,81},{17,0,136},{32,129,4},{68,0,34},{10,0,80}}, {{32,129,4},{68,66,34},{138,36,81},{17,0,136},{32,129,4},{68,66,34},{74,0,80},{16,0,8}}, {{4,66,32},{10,36,80},{17,24,136},{32,129,4},{68,66,34},{10,0,80},{17,0,136},{0,0,0}}}; unsigned char rain [][8][3] PROGMEM = { //In this example the animation is called rain, {{0,2,4},{32,0,0},{1,0,16},{0,0,0},{0,0,64},{2,0,0},{0,0,4},{8,0,0}}, //Paste the array values you got from excel here {{4,0,32},{0,2,4},{32,0,1},{1,0,16},{0,0,0},{0,0,64},{2,0,0},{0,0,0}}, {{0,0,0},{4,0,32},{0,2,4},{32,0,1},{1,0,16},{0,0,0},{0,0,64},{2,0,0}}, {{8,0,0},{0,0,0},{4,0,32},{0,2,4},{32,0,1},{1,0,16},{0,0,0},{0,0,64}}, {{0,0,0},{8,0,0},{0,0,0},{4,0,32},{0,2,4},{32,0,0},{1,0,16},{0,0,0}}, {{0,0,4},{8,0,0},{0,0,0},{4,0,32},{0,2,4},{32,0,0},{1,0,16},{0,0,0}}, {{2,0,0},{0,0,4},{8,0,0},{0,0,0},{4,0,32},{0,2,4},{32,0,0},{0,0,16}}, {{0,0,64},{2,0,0},{0,0,4},{8,0,0},{0,0,0},{4,0,32},{0,0,4},{0,0,0}}, {{1,0,16},{0,0,64},{2,0,0},{0,0,4},{8,0,0},{0,0,0},{4,0,32},{0,0,0}}, {{32,0,0},{1,0,16},{0,0,64},{2,0,0},{0,0,4},{8,0,0},{0,0,0},{4,0,32}}, {{0,0,0},{32,0,0},{1,0,16},{0,0,64},{2,0,0},{0,0,4},{8,0,0},{0,0,0}} }; //When you get to the last frame of your animation, you need to replace the comma with }; unsigned char rotatebox [][8][3] PROGMEM = { {{0,0,0},{63,0,252},{33,0,132},{33,0,132},{33,0,132},{33,0,132},{63,0,252},{0,0,0}}, {{24,0,96},{22,0,88},{33,128,134},{32,128,130},{65,1,4},{97,1,132},{26,0,104},{6,0,24}}, {{12,0,48},{18,0,72},{33,0,132},{64,129,2},{64,129,2},{33,0,132},{18,0,72},{12,0,48}}, {{6,0,24},{26,0,104},{97,1,132},{65,1,4},{32,128,130},{33,128,134},{22,0,88},{24,0,96}}}; unsigned char centralarrowburst [][8][3] PROGMEM = { {{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0}}, {{0,0,0},{0,0,0},{0,0,0},{0,24,0},{0,36,0},{0,66,0},{0,129,0},{0,0,0}}, {{0,0,0},{0,0,0},{0,24,0},{0,36,0},{0,66,0},{0,129,0},{1,0,128},{2,0,64}}, {{0,0,0},{0,24,0},{0,36,0},{0,66,0},{0,129,0},{1,0,128},{2,0,64},{4,0,32}}, {{0,24,0},{0,36,0},{0,66,0},{0,153,0},{1,36,128},{2,66,64},{4,129,32},{8,0,16}}, {{0,36,0},{0,66,0},{0,153,0},{1,36,128},{2,66,64},{4,129,32},{9,0,144},{18,0,72}}, {{0,66,0},{0,153,0},{1,36,128},{2,66,64},{4,129,32},{9,0,144},{18,0,72},{36,0,36}}, {{0,153,0},{1,36,128},{2,66,64},{4,153,32},{9,36,144},{18,66,72},{36,129,36},{73,0,146}}, {{1,36,128},{2,66,64},{4,153,32},{9,36,144},{18,66,72},{36,129,36},{73,0,146},{146,0,73}}, {{2,66,64},{4,153,32},{9,36,144},{18,66,72},{36,129,36},{73,0,146},{146,0,73},{36,0,36}}, {{4,153,32},{9,36,144},{18,66,72},{36,129,36},{73,0,146},{146,0,73},{36,0,36},{72,0,18}}, {{9,36,144},{18,66,72},{36,129,36},{73,0,146},{146,0,73},{36,0,36},{72,0,18},{144,0,9}}, {{18,66,72},{36,129,36},{73,0,146},{146,0,73},{36,0,36},{72,0,18},{144,0,9},{32,0,4}}, {{36,129,36},{73,0,146},{146,0,73},{36,0,36},{72,0,18},{144,0,9},{32,0,4},{64,0,2}}, {{73,0,146},{146,0,73},{36,0,36},{72,0,18},{144,0,9},{32,0,4},{64,0,2},{128,0,1}}, {{146,0,73},{36,0,36},{72,0,18},{144,0,9},{32,0,4},{64,0,2},{128,0,1},{0,0,0}}, {{36,0,36},{72,0,18},{144,0,9},{32,0,4},{64,0,2},{128,0,1},{0,0,0},{0,0,0}}, {{72,0,18},{144,0,9},{32,0,4},{64,0,2},{128,0,1},{0,0,0},{0,0,0},{0,0,0}}, {{144,0,9},{32,0,4},{64,0,2},{128,0,1},{0,0,0},{0,0,0},{0,0,0},{0,0,0}}, {{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0}}}; unsigned char sine [][8][3] PROGMEM = { {{7,128,7},{12,192,12},{24,96,24},{16,32,16},{32,16,32},{96,24,96},{192,12,192},{128,7,128}}, {{15,0,15},{25,128,25},{48,192,48},{32,64,32},{64,32,64},{192,48,192},{128,25,128},{0,15,0}}, {{30,0,30},{51,0,51},{97,128,97},{64,128,64},{128,64,128},{128,97,128},{0,51,0},{0,30,0}}, {{60,0,60},{102,0,102},{195,0,195},{129,0,129},{0,129,0},{0,195,0},{0,102,0},{0,60,0}}, {{120,0,120},{204,0,204},{134,1,134},{2,1,2},{1,2,1},{1,134,1},{0,204,0},{0,120,0}}, {{240,0,240},{152,1,152},{12,3,12},{4,2,4},{2,4,2},{3,12,3},{1,152,1},{0,240,0}}, {{224,1,224},{48,3,48},{24,6,24},{8,4,8},{4,8,4},{6,24,6},{3,48,3},{1,224,1}}, {{192,3,192},{96,6,96},{48,12,48},{16,8,16},{8,16,8},{12,48,12},{6,96,6},{3,192,3}}, {{128,7,128},{192,12,192},{96,24,96},{32,16,32},{16,32,16},{24,96,24},{12,192,12},{7,128,7}}, {{0,15,0},{128,25,128},{192,48,192},{64,32,64},{32,64,32},{48,192,48},{25,128,25},{15,0,15}}, {{0,30,0},{0,51,0},{128,97,128},{128,64,128},{64,128,64},{97,128,97},{51,0,51},{30,0,30}}, {{0,60,0},{0,102,0},{0,195,0},{0,129,0},{129,0,129},{195,0,195},{102,0,102},{60,0,60}}, {{0,120,0},{0,204,0},{1,134,1},{1,2,1},{2,1,2},{134,1,134},{204,0,204},{120,0,120}}, {{0,240,0},{1,152,1},{3,12,3},{2,4,2},{4,2,4},{12,3,12},{152,1,152},{240,0,240}}, {{1,224,1},{3,48,3},{6,24,6},{4,8,4},{8,4,8},{24,6,24},{48,3,48},{224,1,224}}, {{3,192,3},{6,96,6},{12,48,12},{8,16,8},{16,8,16},{48,12,48},{96,6,96},{192,3,192}}}; // ########################################### End of animation definitions !!! ######################################################################### void setup() { pinMode(DataPin,OUTPUT); //Basic setup of pins etc pinMode(ClockPin,OUTPUT); pinMode(LatchPin,OUTPUT); } void display_pattern (unsigned char frame_time,unsigned char frames[][8][3],unsigned char num_frames,unsigned char num_loops) { //My function called run_animation_P - this has been modified to use PROGMEM data byte datasegment; //The display algorithm shifts out the 3 numbers in the array to display row 1 and then drops down a line.... //and continues to output the data for that line. It drops down through each of the 8 rows then resets. It then does the next frame. for(i=0; i < num_loops; i++){ //number of times to play full animation for(x=0; x < num_frames; x++){ //number of frames in the animation for(z=0; z < frame_time; z++){ //times to display each frame for(y=0; y < 8; y++){ //cycle through each layer //write the LED row data to the shift registers for the current layer digitalWrite(LatchPin, 0); shiftOut(DataPin, ClockPin, MSBFIRST, row); datasegment = pgm_read_byte(&(frames[x][y][2])); shiftOut(DataPin, ClockPin, LSBFIRST, datasegment); datasegment = pgm_read_byte(&(frames[x][y][1])); shiftOut(DataPin, ClockPin, LSBFIRST, datasegment); datasegment = pgm_read_byte(&(frames[x][y][0])); shiftOut(DataPin, ClockPin, LSBFIRST, datasegment); row=row/2; //makes shift register act like a ring counter so each row comes on once digitalWrite(LatchPin, 1); delayMicroseconds(700); digitalWrite(LatchPin, 0); delayMicroseconds(10); } row=128; //reset line or "row" counter } } } } void load_stimulus (unsigned char pace, unsigned char chars, unsigned char column_fill [][5][5]){ //change the left most arguement to fit no. of char in text for(int d = 0; d < chars ;d++){ for(int v = 0 ; v < 5 ; v++){ for(int q = 0 ; q < 8 ; q++){ if(q < 5){ current_display [0][q][2] = (current_display [0][q][2] + column_fill [d][v][q]); } } scroll_speed = pace; display_text(scroll_speed,current_display,1,1); shift_columns(); } } } void shift_columns (){ for(int r = 0; r < 8; r++){ for(int f = 0; f < 3; f++){ text_buffer[0][r][f] = current_display[0][r][f]; } } for(int a = 0; a < 8; a++){ for(int b = 0; b <3; b++){ if((text_buffer[0][a][b]) >= 128 ){ temp_cell = text_buffer[0][a][b]; temp_cell = ((temp_cell * 2)-256); text_buffer[0][a][b] = temp_cell; if(b != 0){ text_buffer[0][a][b-1] = text_buffer[0][a][b-1] + 1; } } else{ if((text_buffer[0][a][b]) < 128){ if((text_buffer[0][a][b]) != 0){ text_buffer[0][a][b] = ((current_display[0][a][b]) * 2); } } } } } for(int l = 0; l < 8; l++){ for(int o = 0; o < 3; o++){ current_display[0][l][o] = text_buffer[0][l][o]; } } } void display_text (unsigned char frame_time,unsigned char frames[][8][3],unsigned char num_frames,unsigned char num_loops){ //My function called run_animation_P - this has been modified to use PROGMEM data byte datasegment; //The display algorithm shifts out the 3 numbers in the array to display row 1 and then drops down a line.... //and continues to output the data for that line. It drops down through each of the 8 rows then resets. It then does the next frame. for(i=0; i < num_loops; i++){ //number of times to play full animation for(x=0; x < num_frames; x++){ //number of frames in the animation for(z=0; z < frame_time; z++){ //times to display each frame for(y=0; y < 8; y++){ //cycle through each layer //write the LED row data to the shift registers for the current layer digitalWrite(LatchPin, 0); shiftOut(DataPin, ClockPin, MSBFIRST, row); shiftOut(DataPin, ClockPin, LSBFIRST, (frames[x][y][2])); shiftOut(DataPin, ClockPin, LSBFIRST, (frames[x][y][1])); shiftOut(DataPin, ClockPin, LSBFIRST, (frames[x][y][0])); row=row/2; //makes shift register act like a ring counter so each row comes on once digitalWrite(LatchPin, 1); delayMicroseconds(700); digitalWrite(LatchPin, 0); delayMicroseconds(100); } row=128; //reset line or "row" counter } } } } void loop(){ // ########################################## Animation Playlist ######################################################## unsigned char RS[14][5][5] = {R,A,V,E,SPACE,S,H,A,D,E,S,SPACE,SPACE,SPACE}; load_stimulus(6,14,RS); display_pattern(5,arrows,13,1); display_pattern(5,arrowscont,4,10); display_pattern(5,arrows,13,1); display_pattern(5,arrowscont,4,10); display_pattern(10,centralarrowburst, 20, 4); display_pattern(10,rotatebox, 4, 4); display_pattern(4,rain,11,15); display_pattern(4,sine,16,5); display_pattern(5,arrows,13,1); display_pattern(5,arrowscont,4,10); display_pattern(5,arrows,13,1); display_pattern(5,arrowscont,4,10); display_pattern(10,centralarrowburst, 20, 4); display_pattern(10,rotatebox, 4, 4); display_pattern(4,rain,11,15); display_pattern(4,sine,16,5); display_pattern(5,arrows,13,1); display_pattern(5,arrowscont,4,10); display_pattern(5,arrows,13,1); display_pattern(5,arrowscont,4,10); display_pattern(10,centralarrowburst, 20, 4); display_pattern(10,rotatebox, 4, 4); display_pattern(4,rain,11,15); display_pattern(4,sine,16,5); display_pattern(5,arrows,13,1); display_pattern(5,arrowscont,4,10); display_pattern(5,arrows,13,1); display_pattern(5,arrowscont,4,10); display_pattern(10,centralarrowburst, 20, 4); display_pattern(10,rotatebox, 4, 4); display_pattern(4,rain,11,15); display_pattern(4,sine,16,5); // The whole section will loop back to the start and repeat. }