// Set the led timer
int timeLedPin1 = A1;
int timeLedPin2 = A2;
int timeLedPin3 = A3;
int timeLedPin4 = A4;
long timeSinceGetIn = 0;
// Define player and leds
int speakerPin = D0;
int ledPin = D1;
// Sing the song
int melody [] =
{
//melody set1
2637, 2637, 0, 2637, 0, 2093, 2637, 0, 3136, 0, 0, 0, 1568, 0, 0, 0,
//melody set2
2093, 0, 0, 1568, 0, 0, 1319, 0, 0, 1760, 0, 1976, 0, 1865, 1760, 0,
//melody set3
1568, 2637, 3136, 3520, 0, 2794, 3136, 0, 2637, 0, 2093, 2349, 1976, 0, 0,
//melody set4
2093, 0, 0, 1568, 0, 0, 1319, 0, 0, 1760, 0, 1976, 0, 1865, 1760, 0,
//melody set5
1568, 2637, 3136, 3520, 0, 2794, 3136, 0, 2637, 0, 2093, 2349, 1976, 0, 0
};
//set tempo
int x1 = 8; //control tempo1
int x2 = 7; //control tempo2
int tempo [] =
{
x1, x1, x1, x1,
x1, x1, x1, x1,
x1, x1, x1, x1,
x1, x1, x1, x1,
x1, x1, x1, x1,
x1, x1, x1, x1,
x1, x1, x1, x1,
x1, x1, x1, x1,
x2, x2, x2,
x1, x1, x1, x1,
x1, x1, x1, x1,
x1, x1, x1, x1,
x1, x1, x1, x1,
x1, x1, x1, x1,
x1, x1, x1, x1,
x1, x1, x1, x1,
x2, x2, x2,
x1, x1, x1, x1,
x1, x1, x1, x1,
x1, x1, x1, x1,
};
void setup() {
pinMode (timeLedPin1, OUTPUT);
pinMode (timeLedPin2, OUTPUT);
pinMode (timeLedPin3, OUTPUT);
pinMode (timeLedPin4, OUTPUT);
//Timeled are all off
digitalWrite(timeLedPin1,LOW);
digitalWrite(timeLedPin2,LOW);
digitalWrite(timeLedPin3,LOW);
digitalWrite(timeLedPin4,LOW);
pinMode (speakerPin, OUTPUT);
pinMode (ledPin, OUTPUT);
}
void loop() {
digitalWrite(ledPin, HIGH);
timer();
}
//This is how the timer works
void timer() {
timeSinceGetIn = millis();
if (timeSinceGetIn >0 && timeSinceGetIn <=4000)
{
digitalWrite(timeLedPin1,HIGH);
}
else if (timeSinceGetIn >4000 && timeSinceGetIn <=8000)
{
Serial.println("Yo!");
digitalWrite(timeLedPin1,HIGH);
digitalWrite(timeLedPin2,HIGH);
}
else if (timeSinceGetIn >8000 && timeSinceGetIn <=12000)
{
Serial.println("Are you ready?");
digitalWrite(timeLedPin1,HIGH);
digitalWrite(timeLedPin2,HIGH);
digitalWrite(timeLedPin3,HIGH);
}
else if (timeSinceGetIn >12000)
{
digitalWrite(timeLedPin1,HIGH);
digitalWrite(timeLedPin2,HIGH);
digitalWrite(timeLedPin3,HIGH);
digitalWrite(timeLedPin4,HIGH);
Serial.println("You are doomed!");
digitalWrite(ledPin, HIGH);
playNotes();
Particle.publish("HeyGetOut");
}
}
//This is how the song works
void playNotes(){
for (int thisNote = 0; thisNote <= 77; thisNote++){
int noteDuration = 1000/tempo[thisNote];
tone(speakerPin, melody[thisNote], noteDuration);
delay(tempo[thisNote]);
Serial.println("lalala~ you are doomed.");
//tempos!
int pauseBetweenNotes = noteDuration;
delay(pauseBetweenNotes);
noTone(speakerPin);
Serial.println("lalala~ ");
//leds dancing while playing
digitalWrite(timeLedPin1,HIGH);
digitalWrite(timeLedPin2,LOW);
delay(20);
digitalWrite(timeLedPin3,HIGH);
digitalWrite(timeLedPin4,LOW);
delay(20);
digitalWrite(timeLedPin1,LOW);
digitalWrite(timeLedPin2,HIGH);
digitalWrite(timeLedPin3,LOW);
digitalWrite(timeLedPin4,HIGH);
delay(20);
digitalWrite(timeLedPin4,LOW);
}
}
Click to Expand
Content Rating
Is this a good/useful/informative piece of content to include in the project? Have your say!
You must login before you can post a comment. .