well, there is a light sensor which acts like a switch (purpose on our model is a kind of "scanner") and it would activate some music and keys. It stops when the sensor detects light
#include "pitches.h"
int lightPin= A2;
int green= 13;
int red= 9;
int key1= 53;
int key2= 51;
int key3= 49;
int key4= 47;
int key5= 45;
int key6= 43;
int key7= 41;
int key8= 39;
int key9= 37;
int melody[]={mi,mi,fa,so,so,fa,mi,re,do,do,re,mi,mi,re,re,mi,mi,fa,so,so,fa,mi,re,do,do,re,mi,re,do,do,
re,re,mi,do,re,mi,fa,mi,do,re,mi,fa,mi,re,do,re,mi,mi,fa,so,so,fa,mi,re,do,do,re,mi,re,do,do}; //hohoho
int noteDurations[]={4,4,4,4,4,4,4,4,4,4,4,4,4,8,2,4,4,4,4,4,4,4,4,4,4,4,4,4,8,2,4,4,4,4,4,8,8,4,4,4,8,8,4,4,4,4,4,4,4,4,
4,4,4,4,4,4,4,4,4,8,2}; //huhuhu
void setup()
{
pinMode(green,OUTPUT);
pinMode(red,OUTPUT);
pinMode(53, OUTPUT);
pinMode(51, OUTPUT);
pinMode(49, OUTPUT);
pinMode(47, OUTPUT);
pinMode(45, OUTPUT);
pinMode(43, OUTPUT);
pinMode(41, OUTPUT);
pinMode(39, OUTPUT);
pinMode(37, OUTPUT);
for (int thisNote = 0; thisNote < 63; thisNote++)
{
int noteDuration = 1000/noteDurations[thisNote];
tone(A4, melody[thisNote],noteDuration);
int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);
noTone(A4);
}
}
void loop()
{
int lightLevel= analogRead(lightPin);
lightLevel= map (lightLevel, 0 ,900, 0 ,255);
if (lightLevel > 0 && lightLevel < 255)
{
digitalWrite(green, LOW);
digitalWrite(red, HIGH);
digitalWrite(key3, HIGH);
delay(250);
digitalWrite(key3, LOW);
digitalWrite(key3, HIGH);
delay(250);
digitalWrite(key3, LOW);
digitalWrite(key4, HIGH);
delay(250);
digitalWrite(key4, LOW);
digitalWrite(key5, HIGH);
delay(250);
digitalWrite(key5, LOW);
digitalWrite(key5, HIGH);
delay(250);
digitalWrite(key5, LOW);
digitalWrite(key4, HIGH);
delay(250);
digitalWrite(key4, LOW);
digitalWrite(key3, HIGH);
delay(250);
digitalWrite(key3, LOW);
digitalWrite(key2, HIGH);
delay(250);
digitalWrite(key2, LOW);
digitalWrite(key1, HIGH);
delay(250);
digitalWrite(key1, LOW);
digitalWrite(key1, HIGH);
delay(250);
digitalWrite(key1, LOW);
digitalWrite(key2, HIGH);
delay(250);
digitalWrite(key2, LOW);
digitalWrite(key3, HIGH);
delay(250);
digitalWrite(key3, LOW);
digitalWrite(key3, HIGH);
delay(250);
digitalWrite(key3, LOW);
digitalWrite(key2, HIGH);
delay(125);
digitalWrite(key2, LOW);
digitalWrite(key2, HIGH);
delay(500);
digitalWrite(key2, LOW);
digitalWrite(key3, HIGH);
delay(250);
digitalWrite(key3, LOW);
digitalWrite(key3, HIGH);
delay(250);
digitalWrite(key3, LOW);
digitalWrite(key4, HIGH);
delay(250);
digitalWrite(key4, LOW);
digitalWrite(key5, HIGH);
delay(250);
digitalWrite(key5, LOW);
digitalWrite(key5, HIGH);
delay(250);
digitalWrite(key5, LOW);
digitalWrite(key4, HIGH);
delay(250);
digitalWrite(key4, LOW);
digitalWrite(key3, HIGH);
delay(250);
digitalWrite(key3, LOW);
digitalWrite(key2, HIGH);
delay(250);
digitalWrite(key2, LOW);
digitalWrite(key1, HIGH);
delay(250);
digitalWrite(key1, LOW);
digitalWrite(key1, HIGH);
delay(250);
digitalWrite(key1, LOW);
digitalWrite(key2, HIGH);
delay(250);
digitalWrite(key2, LOW);
digitalWrite(key3, HIGH);
delay(250);
digitalWrite(key3, LOW);
digitalWrite(key2, HIGH);
delay(250);
digitalWrite(key2, LOW);
digitalWrite(key1, HIGH);
delay(125);
digitalWrite(key1, LOW);
digitalWrite(key1, HIGH);
delay(500);
digitalWrite(key1, LOW);
digitalWrite(key2, HIGH);
delay(250);
digitalWrite(key2, LOW);
digitalWrite(key2, HIGH);
delay(250);
digitalWrite(key2, LOW);
digitalWrite(key3, HIGH);
delay(250);
digitalWrite(key3, LOW);
digitalWrite(key1, HIGH);
delay(250);
digitalWrite(key1, LOW);
digitalWrite(key2, HIGH);
delay(250);
digitalWrite(key2, LOW);
digitalWrite(key3, HIGH);
delay(125);
digitalWrite(key3, LOW);
digitalWrite(key4, HIGH);
delay(125);
digitalWrite(key4, LOW);
digitalWrite(key3, HIGH);
delay(250);
digitalWrite(key3, LOW);
digitalWrite(key1, HIGH);
delay(250);
digitalWrite(key1, LOW);
digitalWrite(key2, HIGH);
delay(250);
digitalWrite(key2, LOW);
digitalWrite(key3, HIGH);
delay(125);
digitalWrite(key3, LOW);
digitalWrite(key4, HIGH);
delay(125);
digitalWrite(key4, LOW);
digitalWrite(key3, HIGH);
delay(250);
digitalWrite(key3, LOW);
digitalWrite(key2, HIGH);
delay(250);
digitalWrite(key2, LOW);
digitalWrite(key1, HIGH);
delay(250);
digitalWrite(key1, LOW);
digitalWrite(key2, HIGH);
delay(250);
digitalWrite(key2, LOW);
digitalWrite(key3, HIGH);
delay(250);
digitalWrite(key3, LOW);
digitalWrite(key3, HIGH);
delay(250);
digitalWrite(key3, LOW);
digitalWrite(key4, HIGH);
delay(250);
digitalWrite(key4, LOW);
digitalWrite(key5, HIGH);
delay(250);
digitalWrite(key5, LOW);
digitalWrite(key5, HIGH);
delay(250);
digitalWrite(key5, LOW);
digitalWrite(key4, HIGH);
delay(250);
digitalWrite(key4, LOW);
digitalWrite(key3, HIGH);
delay(250);
digitalWrite(key3, LOW);
digitalWrite(key2, HIGH);
delay(250);
digitalWrite(key2, LOW);
digitalWrite(key1, HIGH);
delay(250);
digitalWrite(key1, LOW);
digitalWrite(key1, HIGH);
delay(250);
digitalWrite(key1, LOW);
digitalWrite(key2, HIGH);
delay(250);
digitalWrite(key2, LOW);
digitalWrite(key3, HIGH);
delay(250);
digitalWrite(key3, LOW);
digitalWrite(key2, HIGH);
delay(250);
digitalWrite(key2, LOW);
digitalWrite(key1, HIGH);
delay(125);
digitalWrite(key1, LOW);
digitalWrite(key1, HIGH);
delay(500);
digitalWrite(key1, LOW);
}
else
{
digitalWrite(green, HIGH);
digitalWrite(red, LOW);
digitalWrite(key3, LOW);
delay(250);
digitalWrite(key3, LOW);
delay(250);
digitalWrite(key4, LOW);
delay(250);
digitalWrite(key5, LOW);
delay(250);
digitalWrite(key5, LOW);
delay(250);
digitalWrite(key4, LOW);
delay(250);
digitalWrite(key3, LOW);
delay(250);
digitalWrite(key2, LOW);
delay(250);
digitalWrite(key1, LOW);
delay(250);
digitalWrite(key1, LOW);
delay(250);
digitalWrite(key2, LOW);
delay(250);
digitalWrite(key3, LOW);
delay(250);
digitalWrite(key3, LOW);
delay(250);
digitalWrite(key2, LOW);
delay(250);
digitalWrite(key2, LOW);
delay(250);
digitalWrite(key3, LOW);
delay(250);
digitalWrite(key3, LOW);
delay(250);
digitalWrite(key4, LOW);
delay(250);
digitalWrite(key5, LOW);
delay(250);
digitalWrite(key5, LOW);
delay(250);
digitalWrite(key4, LOW);
delay(250);
digitalWrite(key3, LOW);
delay(250);
digitalWrite(key2, LOW);
delay(250);
digitalWrite(key1, LOW);
delay(250);
digitalWrite(key1, LOW);
delay(250);
digitalWrite(key2, LOW);
delay(250);
digitalWrite(key3, LOW);
delay(250);
digitalWrite(key2, LOW);
delay(250);
digitalWrite(key1, LOW);
delay(250);
digitalWrite(key1, LOW);
delay(250);
digitalWrite(key2, LOW);
delay(250);
digitalWrite(key2, LOW);
delay(250);
digitalWrite(key3, LOW);
delay(250);
digitalWrite(key1, LOW);
delay(250);
digitalWrite(key2, LOW);
delay(250);
digitalWrite(key3, LOW);
delay(250);
digitalWrite(key4, LOW);
delay(250);
digitalWrite(key3, LOW);
delay(250);
digitalWrite(key1, LOW);
delay(250);
digitalWrite(key2, LOW);
delay(250);
digitalWrite(key3, LOW);
delay(250);
digitalWrite(key4, LOW);
delay(250);
digitalWrite(key3, LOW);
delay(250);
digitalWrite(key2, LOW);
delay(250);
digitalWrite(key1, LOW);
delay(250);
digitalWrite(key2, LOW);
delay(250);
digitalWrite(key3, LOW);
delay(250);
digitalWrite(key3, LOW);
delay(250);
digitalWrite(key4, LOW);
delay(250);
digitalWrite(key5, LOW);
delay(250);
digitalWrite(key5, LOW);
delay(250);
digitalWrite(key4, LOW);
delay(250);
digitalWrite(key3, LOW);
delay(250);
digitalWrite(key2, LOW);
delay(250);
digitalWrite(key1, LOW);
delay(250);
digitalWrite(key1, LOW);
delay(250);
digitalWrite(key2, LOW);
delay(250);
digitalWrite(key3, LOW);
delay(250);
digitalWrite(key2, LOW);
delay(250);
digitalWrite(key1, LOW);
delay(250);
digitalWrite(key1, LOW);
delay(250);
}
}