Created
October 16, 2017 13:27
-
-
Save a-mishra/d44ee33953850ca1b971f4c5e0ec030a to your computer and use it in GitHub Desktop.
Lightshow is an arduino program to switch on/off lights in a sequential manner.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <SoftwareSerial.h> | |
| SoftwareSerial BTSerial(10,11); //Rx|Tx | |
| String instream; | |
| int playSeq = 1; | |
| int pause = 1000; | |
| int tempRow = 6; | |
| boolean Seq1[6][4] = { | |
| {0,0,0,1}, | |
| {0,0,1,0}, | |
| {0,1,0,0}, | |
| {1,0,0,0}, | |
| {0,1,0,0}, | |
| {0,0,1,0} | |
| }; | |
| boolean Seq2[6][4] = { | |
| {1,1,1,0}, | |
| {1,1,0,1}, | |
| {1,0,1,1}, | |
| {0,1,1,1}, | |
| {1,0,1,1}, | |
| {1,1,0,1} | |
| }; | |
| boolean Seq3[7][4] = { | |
| {0,0,0,1}, | |
| {1,0,0,0}, | |
| {1,0,0,1}, | |
| {1,0,1,1}, | |
| {1,1,0,1}, | |
| {1,1,1,1}, | |
| {0,0,0,0} | |
| }; | |
| boolean Seq4[6][4] = { | |
| {1,0,0,1}, | |
| {0,0,1,0}, | |
| {0,1,0,0}, | |
| {1,0,0,1}, | |
| {0,1,0,0}, | |
| {0,0,1,0} | |
| }; | |
| boolean Seq5[4][4] = { | |
| {0,0,1,1}, | |
| {0,1,1,0}, | |
| {1,1,0,0}, | |
| {0,1,1,0} | |
| }; | |
| void setup(){ | |
| Serial.begin(9600); | |
| Serial.println("Firing up Lightshow"); | |
| BTSerial.begin(38400); | |
| pinMode(2,OUTPUT); | |
| pinMode(3,OUTPUT); | |
| pinMode(4,OUTPUT); | |
| pinMode(5,OUTPUT); | |
| } | |
| void loop(){ | |
| if(BTSerial.available()){ | |
| instream = ""; | |
| while(BTSerial.available()) | |
| instream+=char(BTSerial.read()); | |
| if(instream == "Seq1") | |
| playSeq=1; | |
| else if(instream == "Seq2") | |
| playSeq=2; | |
| else if(instream == "Seq3") | |
| playSeq=3; | |
| else if(instream == "Seq4") | |
| playSeq=4; | |
| else if(instream == "Seq5") | |
| playSeq=5; | |
| else if(instream == "Slow") | |
| pause+=200; | |
| else if(instream == "Fast") | |
| pause-=200; | |
| pause=constrain(pause,100,3000); | |
| } | |
| if(Serial.available()){ | |
| instream = ""; | |
| while(Serial.available()) | |
| instream+=char(Serial.read()); | |
| if(instream == "Seq1") | |
| playSeq=1; | |
| else if(instream == "Seq2") | |
| playSeq=2; | |
| else if(instream == "Seq3") | |
| playSeq=3; | |
| else if(instream == "Seq4") | |
| playSeq=4; | |
| else if(instream == "Seq5") | |
| playSeq=5; | |
| else if(instream == "Slow") | |
| pause+=200; | |
| else if(instream == "Fast") | |
| pause-=200; | |
| pause=constrain(pause,100,3000); | |
| } | |
| switch(playSeq){ | |
| case 1: player(Seq1);tempRow=6;break; | |
| case 2: player(Seq2);tempRow=6;break; | |
| case 3: player(Seq3);tempRow=7;break; | |
| case 4: player(Seq4);tempRow=6;break; | |
| case 5: player(Seq5);tempRow=4;break; | |
| default: player(Seq1);tempRow=6;break; | |
| } | |
| } | |
| void player(boolean Seq[][4]){ | |
| //sizeof(Seq) / sizeof(Seq[0]); | |
| int rows = tempRow; | |
| Serial.print("\n");Serial.print("rows:");Serial.print(rows); | |
| // int cols = sizeof(Seq[0]) / sizeof(Seq[0][0]); | |
| int cols = sizeof(Seq[0]); | |
| Serial.print(" Cols");Serial.print(cols);Serial.print("\n"); | |
| for(int i=0;i<rows;i++){ | |
| for(int j=0;j<cols;j++){ | |
| Serial.print(Seq[i][j]); | |
| digitalWrite(j+2,Seq[i][j]); | |
| Serial.print(", "); | |
| } | |
| Serial.print("\n"); | |
| if(BTSerial.available()) | |
| break; | |
| else if(Serial.available()) | |
| break; | |
| delay(pause); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment