int photoCellPin = A5;
int photoCellReading = 0;
int ledPin = D2;
int ledBrightness1 = 0;
//below are for the soil moisture sensor
int rainPin = A0;
int greenLED = D6;
//int thresholdValue = 800;
int sensorValue = 0;
int speakerPin = D3;
int melody1[] = {1046,1046,1568,1568,1760,1760,1568,1568};
int melody2[] = {1967,1760,1568,1397,1318,1175,1046};
int noteDurations[] = {4,8,8,4,4,4,4,4 };
// store the time when you last published
int last_published = -1;
void setup()
{
pinMode( speakerPin, OUTPUT );
pinMode(ledPin, OUTPUT);
Particle.variable("light", &photoCellReading, INT);
pinMode(rainPin, INPUT);
pinMode(greenLED, OUTPUT);
digitalWrite(greenLED, LOW);
Particle.variable("rain", &sensorValue, INT);
}
void spreadsheet( ){
if( last_published + 60000 < millis() ){
Particle.publish( "log_to_spreadsheet", String( photoCellReading ) );
last_published = millis();
}
}
void loop()
{
sensorValue = analogRead(rainPin);
if(sensorValue > 4000){
playNotes2();
digitalWrite(greenLED, LOW);
}
else(sensorValue < 4000);
{
digitalWrite(greenLED, HIGH);
}
photoCellReading = analogRead(photoCellPin);
//TOO LIGHT PLAY A SONG
if (photoCellReading > 2200)
{
playNotes1();
}
else if(photoCellReading < 1000)
{
//TOO DARK GIVE A LIGHT
digitalWrite( ledPin, HIGH );
delay(1500);
digitalWrite( ledPin, LOW );
}
else
{
analogWrite(ledPin, 0);
}
delay(500);
spreadsheet( );
}
void playNotes1()
{
for (int thisNote = 0; thisNote < 8; thisNote++) {
int noteDuration = 1000/noteDurations[thisNote];
tone(speakerPin, melody1[thisNote],noteDuration);
int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);
noTone(speakerPin);
}
}
void playNotes2()
{
for (int thisNote = 0; thisNote < 8; thisNote++) {
int noteDuration = 1000/noteDurations[thisNote];
tone(speakerPin, melody2[thisNote],noteDuration);
int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);
noTone(speakerPin);
}
}
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. .