#include "LedControl.h" #include #include //display variables LedControl lc=LedControl(12,11,10,4); int devices=lc.getDeviceCount(); unsigned int m[8]={0,0,0,0,0,0,0,0}; unsigned int diagonals[]={0xCCCC,0x9999,0x3333,0x6666,0xCCCC,0x9999,0x3333,0x6666,0xCCCC,0x9999,0x3333,0x6666}; int defaultBrightness=4; //control variables int currentFn=1; int stepr1=0; int stepr2=0; int counter1=0; int rhythmic=0; //timing variables unsigned long tempo=5; unsigned long longPressTime=800;; unsigned long printTime; unsigned long currentTime; unsigned long loopTime; //input variables int buttonPin=8; int val; // variable for reading the pin status int val2; // variable for reading the delayed/debounced status int btnState; // variable to hold the button state unsigned long btnDownTime; //animation variables FLASH_TABLE(unsigned int,linamation,4, {1505,962,4066,6103},{2464,1986,4066,14279},{2976,1986,8130,12263},{4994,4034,8134,28578}, {5958,3970,16326,20386},{14150,3970,16262,57294},{11778,8070,32646,40782},{28290,7942,32646,48974}, {20098,16134,65294,16006},{56590,15878,65294,32415},{47364,32270,65294,32415},{47364,32270,65038,64799}, {14852,64526,65054,64813},{31254,64524,65055,64812},{29215,64524,64543,64060},{62479,63516,64573,64030}, {58413,63516,64573,64030},{59432,61469,63549,63071},{51256,61469,63549,62559},{53272,57405,61501,60541}, {36957,57401,61565,59577},{45149,49209,61565,51385},{8241,49273,57465,53757},{24753,32889,57593,37245}, {16561,32889,49401,45437},{49529,241,49657,8945},{33129,241,33273,25331},{33120,241,33265,18171}, {736,497,1009,50683},{722,481,1011,34281},{723,480,1011,36320},{1475,992,2019,3056}); const boolean bouncy[16][8]={ {1,1,1,1,1,1,1,1},{1,1,1,1,1,1,0,0},{1,1,1,1,0,0,0,0},{1,1,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0},{1,0,0,0,0,0,0,0},{1,1,0,0,0,0,0,0},{1,1,1,0,0,0,0,0}, {1,1,1,1,0,0,0,0},{1,1,1,0,0,0,0,0},{1,1,0,0,0,0,0,0},{1,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0},{1,1,0,0,0,0,0,0},{1,1,1,1,0,0,0,0},{1,1,1,1,1,1,0,0} }; const int sparkleSize=50; byte sparkleSet[50][3]; //match first lenght to sparkleSize const boolean flameBase[8][16]={ {1,0,0,0,1,1,1,1,1,1,1,1,1,1,1,0}, {1,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0}, {1,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0}, {1,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0}, {1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,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,0} }; const byte flameHeight[16]= {0,0,0,1,2,2,2,3,4,6,8,6,2,2,2,1}; const boolean tron1[8][16]={ {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,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,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1} }; const boolean tron2[8][16]={ {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,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,1,1,1,1,1,1,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,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} }; const boolean tron3[8][16]={ {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {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,0,0,0,0,0,0,0,0,0,0} }; const boolean tron4[8][16]={ {1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {1,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,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,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} }; const boolean tron5[8][16]={ {0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0}, {0,0,0,0,0,0,1,1,1,1,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,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,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} }; void setup() { //initialize the controller chips for(int address=0;address>8)); lc.setRow(1,row,byte(m[row])); lc.setRow(2,row,byte(m[row])); lc.setRow(3,row,byte(m[row]>>8)); } //Serial.println(millis()-printStart); //Serial.println(currentFn); } // Reverse the order of bits in a byte. unsigned char Bit_Reverse( unsigned char x ) { x = ((x >> 1) & 0x55) | ((x << 1) & 0xaa); x = ((x >> 2) & 0x33) | ((x << 2) & 0xcc); x = ((x >> 4) & 0x0f) | ((x << 4) & 0xf0); return x; } void loading(){ float phase=(float(stepr2)/64)*PI; int targetLed=int(sin(phase)*5+0.5); //int truncates, so add a half first to round instead lc.setRow(1,0,0); lc.setLed(1,0,7-targetLed,true); lc.setRow(2,0,0); lc.setLed(2,0,7-targetLed,true); stepr2++; if(stepr2==64){stepr2=0;} delay(10); } void sineLine(){ for(int row=0;row<1;row++){m[row]=linamation[stepr1][stepr2];} for(int row=0;row<1;row++){ lc.setRow(0,row,byte(m[row]>>8)); lc.setRow(1,row,byte(m[row])); lc.setRow(2,row,byte(m[row])); lc.setRow(3,row,byte(m[row]>>8)); } stepr2++; if(stepr2==4){ stepr2=0; stepr1++; if(stepr1==0){for(int address=0;address=emberDel){stepr2=0;} for(int row=0;row<8;row++){ //traspose to m for(int col=0;col<16;col++){ if(flameBase[row][col] || row<=flandom[col]-1 || (col==emberCol && row==stepr2)){bitSet(m[row],col);} else{bitClear(m[row],col);} } } printArray(); //} } void tronimation(){ static int shift1r=0; static int shift2c=0; static int shift3c=0; static int shift4r=0; static int shift5c=0; if(stepr1==0){ shift1r=0; shift2c=0; shift3c=0; shift4r=0; shift5c=0; } if(stepr1<40){ stepr1++; } else{ stepr1=1; boolean tronTotal[8][16]={ {0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1}, {0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,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,0,0,0,0,0,0,0,0,0,0,0,0} }; if(stepr2>0&&stepr2<7){shift4r++;} else if(stepr2==10){shift5c++;} else if(stepr2>11 && stepr2<19){shift5c--;} else if(stepr2>40 && stepr2<47){shift2c++;} else if(stepr2>70 && stepr2<78){shift3c++;} else if(stepr2>100 && stepr2<105){shift1r--;} else if(stepr2>130 && stepr2<137){shift5c++;} else if(stepr2>160 && stepr2<164){shift1r--;} else if(stepr2>190 && stepr2<197){shift2c--;} else if(stepr2>220 && stepr2<227){shift4r--;} else if(stepr2>250 && stepr2<258){shift3c--;} else if(stepr2>280 && stepr2<288){shift1r++;} for(byte row=0;row<8;row++){ for(byte col=0;col<16;col++){ if(row-shift1r>=0 && row-shift1r<8){tronTotal[row][col]|=tron1[row-shift1r][col];} if(col-shift2c>=0 && col-shift2c<16){tronTotal[row][col]|=tron2[row][col-shift2c];} if(col-shift3c>=0 && col-shift3c<16){tronTotal[row][col]|=tron3[row][col-shift3c];} if(row-shift4r>=0 && row-shift4r<8){tronTotal[row][col]|=tron4[row-shift4r][col];} if(col-shift5c>=0 && col-shift5c<16){tronTotal[row][col]|=tron5[row][col-shift5c];} } //Serial.print("freeMemory()=");Serial.println(freeMemory());delay(50); } for(byte row=0;row<8;row++){ for(byte col=0;col<16;col++){ bitWrite(m[row],col,tronTotal[row][col]); } } //Serial.print("freeMemory()=");Serial.println(freeMemory()); printArray(); stepr2++; if(stepr2>=300){stepr2=0;} } } void aioxoia(){ if(stepr1<40){ stepr1++; } else{ stepr1=1; boolean aioxoia[8][16]={ {0,0,0,1,0,0,0,1,0,1,0,0,0,0,0,0}, {0,0,1,0,1,0,0,1,0,1,0,0,0,0,0,0}, {0,0,1,0,1,0,0,1,1,1,0,0,0,0,0,0}, {0,0,1,0,1,0,0,1,0,1,0,0,0,0,0,0}, {0,0,0,1,0,0,0,1,1,1,0,0,0,0,0,0}, {0,0,0,0,0,0,0,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,0,0,0} }; // boolean aioxoia[8][16]={ // {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,0,0,0}, // {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, // {0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, // {1,0,0,1,0,1,1,1,1,0,0,0,0,0,0,0}, // {1,0,1,0,1,1,1,0,1,0,0,0,0,0,0,0}, // {0,1,0,1,0,1,0,1,0,0,0,0,0,0,0,0} // }; // boolean aioxoia[8][16]={ // {0,0,0,0,1,1,1,0,0,1,1,1,0,0,0,0}, // {0,0,0,1,0,1,1,0,0,1,0,1,0,0,0,0}, // {0,0,0,1,0,1,1,1,0,0,1,0,0,0,0,0}, // {0,0,0,0,1,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,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} // }; for(byte row=0;row<8;row++){ for(byte col=0;col<16;col++){ bitWrite(m[row],col,aioxoia[row][col]); } } //Serial.print("freeMemory()=");Serial.println(freeMemory()); printArray(); stepr2++; if(stepr2>=300){stepr2=0;} delay(1000); } } void horns(){ if(stepr1==0){ boolean hornpat[8][16]={ {0,0,0,0,0,1,1,1,1,1,1,0,0,0,0,0}, {0,0,0,0,0,1,1,1,1,1,1,1,0,0,0,0}, {0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0}, {0,0,0,0,1,1,1,1,1,1,1,1,1,1,0,0}, {0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1}, {0,0,0,0,0,1,1,1,0,0,0,0,0,0,1,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} }; for(byte row=0;row<8;row++){ for(byte col=0;col<16;col++){ bitWrite(m[row],col,hornpat[row][col]); } } printArray(); } else{ stepr1++; if(stepr1>2000){stepr1=0;} } } void eyes(){ if(stepr1==0){ boolean eyepat[8][16]={ {0,1,1,0,1,1,0,0,0,0,0,0,0,0,0,0}, {0,0,1,0,1,1,0,0,0,0,0,0,0,0,0,0}, {0,0,0,1,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,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,0,0,0,0,0,0,0,0,0,0} }; for(byte row=0;row<8;row++){ for(byte col=0;col<16;col++){ bitWrite(m[row],col,eyepat[row][col]); } } printArray(); } else{ stepr1++; if(stepr1>2000){stepr1=0;} } } void pipes(){ if(stepr1<20){stepr1++;} else{ stepr1=0; for(int row=0;row<8;row++){ //traspose to m for(int col=0;col<16;col++){ if( row==3 || row==4 ){bitSet(m[row],col);} else if((row==0||row==1)&&(col%4==stepr2 || col%4==stepr2-1)){bitSet(m[row],col);} else if((row==6||row==7)&&(col%4==4-stepr2 || col%4==3-stepr2)){bitSet(m[row],col);} else{bitClear(m[row],col);} } } printArray(); stepr2++; if(stepr2>=4){stepr2=0;} } } ///////////////////////////////////////////////////////// ///////######## RHYTHMIC ANIMATIONS ########///////////// ///////////////////////////////////////////////////////// void rhythmic01(){ for(int row=0;row<8;row++){ if(row==stepr1 || row==stepr1+1 || row==stepr1-7){m[row]=0;} else{m[row]=65535;} } stepr1++; if (stepr1==8){stepr1=0;} printArray(); } void rhythmic02(){ int intensity; if(stepr1==0){ for(int row=0;row<8;row++){ m[row]=random(65535); } } if(stepr1<4){intensity=5*stepr1;} else{intensity=24-3*stepr1;} for(int address=0;addresslongPressTime){ //Serial.println(pressTime); tempo=pressTime/64; loopTime=millis(); //Serial.println(tempo); rhythmic=1; } else{ currentFn++; for(int address=0;address=(loopTime+tempo)){ //Serial.println(currentTime); loopTime+=tempo; if(rhythmic){ switch(currentFn){ case 1: rhythmic01(); break; case 2: rhythmic02(); break; case 3: rhythmic03(); break; case 4: rhythmic04(); break; case 5: rhythmic05(); break; case 6: wavimation(); break; default: currentFn=1; break; } } else{ switch(currentFn){ case 1: loading(); break; case 2: sineLine(); break; case 4: crazyAnts(); break; case 3: sparkly(); break; case 5: valkyrie(); break; case 6: tronimation(); break; case 8: horns(); break; case 9: eyes(); break; case 7: pipes(); break; default: currentFn=1; break; } } } }