Skip to content

Instantly share code, notes, and snippets.

@m4rk3r
Last active August 29, 2015 14:06
Show Gist options
  • Save m4rk3r/5f0039941f152434f46f to your computer and use it in GitHub Desktop.
Save m4rk3r/5f0039941f152434f46f to your computer and use it in GitHub Desktop.
#include "pitches.h"
int pitch = NOTE_C8;
float notes[] = { 18, 20, 25, 32 };
int notecount = 4;
int couplet = 3;
int darkness = 50;
void setup(){
Serial.begin(9600);
}
void loop(){
int reading = analogRead(0);
Serial.println(reading);
if(reading <= darkness){
for(int repeat=0; repeat < couplet; repeat++){
for(int idx=0; idx < notecount; idx++){
int noteDuration = notes[idx];
tone(8, pitch);
delay(noteDuration);
// stop the tone playing:
noTone(8);
delay(noteDuration);
}
// delay after couplet
delay(random(350,600));
}
// delay after repeating song
delay(random(200,300));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment