/*
* For Automated Mung Bean Sprouts growing machine
*
* Watering every 2 hours
* play music when watering
*
* Relay pin 12
* speaker pin 8
*
* created 22 Jan 2017
*
* updated 24 Jan 2017
* -Added one more song (Butterfly)
* -Randomly select a song (Schoolbell or Butterfly)
* -watering every an hour from every 2 hours.
* -increase watering time (Schoolbell - play 3 times, Butterfly - play 2 times)
*
*by Douglas Changsoo Park
*
*/
#include <SimpleTimer.h>
#include "pitches.h"
int relay = 12;
int melodyPin = 8;
SimpleTimer timer;
int schoolbell_melody[] = {
NOTE_G4, NOTE_G4, NOTE_A4, NOTE_A4, NOTE_G4, NOTE_G4, NOTE_E4, NOTE_G4, NOTE_G4, NOTE_E4, NOTE_E4, NOTE_D4, 0,
NOTE_G4, NOTE_G4, NOTE_A4, NOTE_A4, NOTE_G4, NOTE_G4, NOTE_E4, NOTE_G4, NOTE_E4, NOTE_D4, NOTE_E4, NOTE_C4, 0 };
int schoolbell_noteDurations[] = { 1,1,1,1, 1,1,2, 1,1,1,1, 3,1, 1,1,1,1, 1,1,2, 1,1,1,1, 3,1 };
int butterfly_melody[] = {
NOTE_G4,NOTE_E4,NOTE_E4,NOTE_F4,NOTE_D4,NOTE_D4,NOTE_C4,NOTE_D4,NOTE_E4,NOTE_F4,NOTE_G4,NOTE_G4,NOTE_G4,
NOTE_G4,NOTE_E4,NOTE_E4,NOTE_E4,NOTE_F4,NOTE_D4,NOTE_D4,NOTE_C4,NOTE_E4,NOTE_G4,NOTE_G4,NOTE_E4,NOTE_E4,NOTE_E4,0,
NOTE_D4,NOTE_D4,NOTE_D4,NOTE_D4,NOTE_D4,NOTE_E4,NOTE_F4,NOTE_E4,NOTE_E4,NOTE_E4,NOTE_E4,NOTE_E4,NOTE_F4,NOTE_G4,
NOTE_G4,NOTE_E4,NOTE_E4,NOTE_F4,NOTE_D4,NOTE_D4,NOTE_C4,NOTE_E4,NOTE_G4,NOTE_G4,NOTE_E4,NOTE_E4,NOTE_E4,0
};
int butterflyNoteDurations[] = {
1,1,2,1,1,2, 1,1,1,1,1,1,2, 1,1,1,1,1,1,2, 1,1,1,1,1,1,3,1,
1,1,1,1,1,1,2,1,1,1,1,1,1,2, 1,1,2,1,1,2,1,1,1,1,1,1,3,1
};
void setup() {
// put your setup code here, to run once:
pinMode(relay, OUTPUT);
digitalWrite(relay, HIGH);
//timer.setInterval(7200000, watering);
timer.setInterval(3600000, watering);
//timer.setInterval(25000, watering); // Test Mode
}
void loop() {
// put your main code here, to run repeatedly:
timer.run();
}
void watering() {
digitalWrite(relay, LOW);
int song = random(1,3);
if(song == 1) {
music_schoolBell();
music_schoolBell();
music_schoolBell();
} else {
music_butterfly();
music_butterfly();
}
digitalWrite(relay, HIGH);
noTone(8);
}
void music_schoolBell() {
int size = sizeof(schoolbell_melody) / sizeof(int);
for(int thisNote = 0; thisNote < size; thisNote++) {
int noteDuration = 250 * schoolbell_noteDurations[thisNote];
tone(melodyPin, schoolbell_melody[thisNote], noteDuration);
int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);
noTone(melodyPin);
}
}
void music_butterfly(){
int size = sizeof(butterfly_melody) / sizeof(int);
for (int thisNote = 0; thisNote < size; thisNote++) {
int noteDuration = 250 * butterflyNoteDurations[thisNote];
tone(melodyPin, butterfly_melody[thisNote], noteDuration);
int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);
noTone(melodyPin);
}
}
Comments