//musical chairs //jmc int d = 25; int d2 = 50; int melody[] = {262, 196, 196, 220, 196, 0, 247, 262}; int noteDurations[] = {4, 8, 8, 4, 4, 4, 4, 4}; int duration0; int duration1; int duration2; void setup() { Serial.begin(9600); pinMode(13, OUTPUT); pinMode(12, OUTPUT); pinMode(11, OUTPUT); pinMode(10, OUTPUT); pinMode(9, OUTPUT); pinMode(8, OUTPUT); pinMode(7, OUTPUT); pinMode(6, OUTPUT); } void loop() { Serial.println(analogRead(3)); delay(100); int pot = analogRead(3); int fsr0 = analogRead(0); int toney0 = map(fsr0, 0, 1024, 20, 200); int color0 = map(fsr0, 100, 850, 4, 12); int fsr1 = analogRead(1); int toney1 = map(fsr1, 0, 1024, 200, 300); int color1 = map(fsr1, 100, 850, 4, 12); int fsr2 = analogRead(2); int toney2 = map(fsr2, 0, 1024, 300, 400); int color2 = map(fsr2, 100, 850, 4, 12); //If no sensors are pressed turn everything off and don't play noise. if ((fsr0 == 0)&&(fsr1==0)&&(fsr2==0)) {digitalWrite(13, LOW);delay(d);digitalWrite(12, LOW);delay(d);digitalWrite(11, LOW);delay(d);digitalWrite(10, LOW);delay(d);digitalWrite(9, LOW);delay(d);digitalWrite(8, LOW);delay(d);digitalWrite(7, LOW);delay(d);digitalWrite(6, LOW);delay(d); noTone(5);} //If all the lights are on, play Skunk in the Barnyard. while ((digitalRead(13) == HIGH)&&(digitalRead(12) == HIGH)&&(digitalRead(11) == HIGH)&&(digitalRead(10) == HIGH)&&(digitalRead(9) == HIGH)&&(digitalRead(8) == HIGH)&&(digitalRead(7) == HIGH)&&(digitalRead(6) == HIGH)){ digitalWrite(13, LOW);delay(d2);digitalWrite(12, LOW);delay(d2);digitalWrite(11, LOW);delay(d2);digitalWrite(10, LOW);delay(d2);digitalWrite(9, LOW);delay(d2);digitalWrite(8, LOW);delay(d2);digitalWrite(7, LOW);delay(d2);digitalWrite(6, LOW);delay(d2); noTone(5); for (int thisNote = 0; thisNote < 8; thisNote++) { int noteDuration = 1000/noteDurations[thisNote]; tone(5, melody[thisNote], noteDuration); int ranny = random(6,13); digitalWrite(ranny, HIGH); int pauseBetweenNotes = noteDuration * 1.30; delay(pauseBetweenNotes); } } if (fsr0 > 3){ if ((pot < 1024)&&(pot > 683)) {duration0 = 30;} if ((pot < 683)&&(pot >341)) {duration0 = 150;} if ((pot < 341)&&(pot >0)) {duration0 = fsr0;} digitalWrite(color0, HIGH); tone(5, toney0, duration0); } if (fsr1 > 3){ if ((pot < 1024)&&(pot > 683)) {duration1 = 30;} if ((pot < 683)&&(pot >341)) {duration1 = 150;} if ((pot < 341)&&(pot >0)) {duration1 = fsr1;} digitalWrite(color1, HIGH); tone(5, toney1, duration1); } if (fsr2 > 3){ if ((pot < 1024)&&(pot > 683)) {duration2 = 30;} if ((pot < 683)&&(pot >341)) {duration2 = 150;} if ((pot < 341)&&(pot >0)) {duration2 = fsr2;} digitalWrite(color2, HIGH); tone(5, toney2, duration2); } delay(10); }