Pages: [1]   Go Down
Author Topic: manual control of a melody  (Read 385 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 24
I Love YaBB 2!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have a small but simple question, I guess. Right now, with the example of the tutorial I am able to play a melody with my arduino and a piezo speaker. With the code I am able to adjust the melody, the speed and the intervals in between the tones rather easy. However, I want to manually tell the arduino when to play the next tone by pressing a button. Is this possible?

For example, if I have a melody cddceeccee, can I then play the first note (c) on the first push on the button, the second tone (d) on the second push of the button, the third note (d) on after that? This way I could manually determine the speed and rhythm of the song...?
Ofcourse I know the basics of reading a digital switch button, but I don't now how to let that button progress a tone by each press. Who can help me out here?
Logged

New Jersey
Offline Offline
Full Member
***
Karma: 0
Posts: 193
Ard at work
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Working from memory, there's a loop that toggles the audio pin high/low at a speed determined by the note (frequency) for a certain duration (actually a certain number of cycles depending on the frequency).

Sounds like you should change that loop's exit condition so that you stay in it until the next button press, rather than after a given number of cycles.

You may want to debouce that button press, tho.
Logged

----------
Mathieu

Pages: [1]   Go Up
Jump to: