/* Template File For User Generated Content. This sketch allows user generated content to be uploaded to Rave Shades LED glasses. http://www.instructables.com/id/Rave-Shades-The-Self-Assembly-LED-Glasses-Kit/ created 11 Apr 2013 by Frederick T. Ford This example code is in the public domain. */ #include #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 !!! ########################################################################### //Paste setup code from the aniamtion editor, along with the data cells here. Watch the video for step by step instructions. unsigned char light [][8][3] PROGMEM = { {{255,255,255},{255,255,255},{255,255,255},{255,255,255},{255,255,255},{255,255,255},{255,255,255},{255,255,255}}, {{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0}}}; //For scrolling text write: unsigned char nameofyourchoice[thenumberofcharactersinthephase][5][5] = {P,H,A,S,E,SPACE,S,P,E,L,T,SPACE,O,U,T,SPACE,I,N,SPACE,L,E,T,T,E,R,S,SPACE,SPACE,SPACE}; //Here is an example called turn_up, with 19 characters and says "turn up the bass" unsigned char turn_up[19][5][5] = {T,U,R,N,SPACE,U,P,SPACE,T,H,E,SPACE,B,A,S,S,SPACE,SPACE,SPACE}; // ########################################### 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) { byte datasegment; 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 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; 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 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 ######################################################## //To display scrolling text animation play write: load_stimulus(scrollingspeed,thenumberofcharactersinthephase, nameofthephasetocall); where the speed is a number from 1 to 255, //Here is an example called turn_up, with a scroll speed of 4 and made up of 19 characters load_stimulus(4,19,turn_up); //To call animation write: display_pattern(speed,nameofanimation,numberofframes2,howmanytimestoplay); //Here is an example called light, with a speed of 4 and made up of 2 frames display_pattern(4,light,2,25); }