The code is below. It's long, but because I did a long song, this was unavoidable. It is mostly repetition.
const int buttonPin = 2;
const int led1 = 3;
const int led2 = 4;
const int led3 = 5;
const int led4 = 6;
const int led5 = 7;
const int led6 = 8;
int musicMarker = 0;
int note = 0;
int buttonDelay = 50;
int lightDelay = 100;
void setup(){
Serial.begin(9600);
pinMode(buttonPin, INPUT);
digitalWrite(buttonPin, HIGH);
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
pinMode(led5, OUTPUT);
pinMode(led6, OUTPUT);
}
void loop(){
if(digitalRead(buttonPin)==0){
musicMarker ++;
delay(buttonDelay);
}
if(musicMarker == 1){
note = 1;
}else if(musicMarker == 2){
note = 1;
}else if(musicMarker == 3){
note = 5;
}else if(musicMarker == 4){
note = 5;
}else if(musicMarker == 5){
note = 6;
}else if(musicMarker == 6){
note = 6;
}else if(musicMarker == 7){
note = 5;
}else if(musicMarker == 8){
note = 4;
}else if(musicMarker == 9){
note = 4;
}else if(musicMarker == 10){
note = 3;
}else if(musicMarker == 11){
note = 3;
}else if(musicMarker == 12){
note = 2;
}else if(musicMarker == 13){
note = 2;
}else if(musicMarker == 14){
note = 1;
}else if(musicMarker == 15){
note = 5;
}else if(musicMarker == 16){
note = 5;
}else if(musicMarker == 17){
note = 4;
}else if(musicMarker == 18){
note = 4;
}else if(musicMarker == 19){
note = 3;
}else if(musicMarker == 20){
note = 3;
}else if(musicMarker == 21){
note = 2;
}else if(musicMarker == 22){
note = 5;
}else if(musicMarker == 23){
note = 5;
}else if(musicMarker == 24){
note = 4;
}else if(musicMarker == 25){
note = 4;
}else if(musicMarker == 26){
note = 3;
}else if(musicMarker == 27){
note = 3;
}else if(musicMarker == 28){
note = 2;
}else if(musicMarker == 29){
note = 1;
}else if(musicMarker == 30){
note = 1;
}else if(musicMarker == 31){
note = 5;
}else if(musicMarker == 32){
note = 5;
}else if(musicMarker == 33){
note = 6;
}else if(musicMarker == 34){
note = 6;
}else if(musicMarker == 35){
note = 5;
}else if(musicMarker == 36){
note = 4;
}else if(musicMarker == 37){
note = 4;
}else if(musicMarker == 38){
note = 3;
}else if(musicMarker == 39){
note = 3;
}else if(musicMarker == 40){
note = 2;
}else if(musicMarker == 41){
note = 2;
}else if(musicMarker == 42){
note = 1;
}else{
note = 0;
musicMarker = 0;
}
if(note == 1){
digitalWrite(led1, HIGH);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
digitalWrite(led6, LOW);
delay(lightDelay);
digitalWrite(led1, LOW);
}else if(note == 2){
digitalWrite(led1, LOW);
digitalWrite(led2, HIGH);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
digitalWrite(led6, LOW);
delay(lightDelay);
digitalWrite(led2, LOW);
}else if(note == 3){
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, HIGH);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
digitalWrite(led6, LOW);
delay(lightDelay);
digitalWrite(led3, LOW);
}else if(note == 4){
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, HIGH);
digitalWrite(led5, LOW);
digitalWrite(led6, LOW);
delay(lightDelay);
digitalWrite(led4, LOW);
}else if(note == 5){
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
digitalWrite(led5, HIGH);
digitalWrite(led6, LOW);
delay(lightDelay);
digitalWrite(led5, LOW);
}else if(note == 6){
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
digitalWrite(led6, HIGH);
delay(lightDelay);
digitalWrite(led6, LOW);
}else{
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
digitalWrite(led6, LOW);
}
}
This comment has been removed by the author.
ReplyDeleteNERDDD
ReplyDelete