Skip to content

Commit

Permalink
Play with tone function.
Browse files Browse the repository at this point in the history
  • Loading branch information
two-pack committed Jul 17, 2014
1 parent 7a19eb9 commit 89c8550
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions speaker/speaker.ino
@@ -0,0 +1,35 @@
// example of tone.
const int SWITCH = 0;
const int SPEAKER = 9;

const int scale[] = {261, 293, 329, 349, 392, 440, 493, 523};

volatile boolean state = true;

void play() {
for(int i = 0; i < 8; i++) {
if(state) {
break;
}
tone(SPEAKER, scale[i]);
delay(250);
}
noTone(SPEAKER);
delay(250);
}

void stop() {
noTone(SPEAKER);
state = !state;
delay(100);
}

void setup() {
Serial.begin(9600);
pinMode(SPEAKER, OUTPUT);
attachInterrupt(SWITCH, stop, RISING);
}

void loop() {
play();
}

0 comments on commit 89c8550

Please sign in to comment.