This example shows how to use the tone() command to play different notes on multiple outputs.
The tone() command works by taking over one of the Atmega's internal timers, setting it to the frequency you want, and using the timer to pulse an output pin. Since it's only using one timer, you can only play one note at a time. You can, however, play notes on multiple pins sequentially. To do this, you need to turn the timer off for one pin before moving on to the next.
Hardware Requirements :
* (3) 8-ohm speakers
* (3) 100 ohm resistor
* breadboard
* hook up wire
Circuit :
Code :
void setup() {
}
void loop() {
// turn off tone function for pin 8:
noTone(8);
// play a note on pin 6 for 200 ms:
tone(6, 440, 200);
delay(200);
// turn off tone function for pin 6:
noTone(6);
// play a note on pin 7 for 500 ms:
tone(7, 494, 500);
delay(500);
// turn off tone function for pin 7:
noTone(7);
// play a note on pin 8 for 500 ms:
tone(8, 523, 300);
delay(300);
}
Source : www.arduino.cc
The tone() command works by taking over one of the Atmega's internal timers, setting it to the frequency you want, and using the timer to pulse an output pin. Since it's only using one timer, you can only play one note at a time. You can, however, play notes on multiple pins sequentially. To do this, you need to turn the timer off for one pin before moving on to the next.
Hardware Requirements :
* (3) 8-ohm speakers
* (3) 100 ohm resistor
* breadboard
* hook up wire
Circuit :
(This Circuit was made in Fritzing)
Code :
void setup() {
}
void loop() {
// turn off tone function for pin 8:
noTone(8);
// play a note on pin 6 for 200 ms:
tone(6, 440, 200);
delay(200);
// turn off tone function for pin 6:
noTone(6);
// play a note on pin 7 for 500 ms:
tone(7, 494, 500);
delay(500);
// turn off tone function for pin 7:
noTone(7);
// play a note on pin 8 for 500 ms:
tone(8, 523, 300);
delay(300);
}
Source : www.arduino.cc
No comments:
Post a Comment