Need music help for an old newbee
Irone
Posts: 116
I copied a very simple program from "Whats a Microcontroller" to see how you put a pause in a song. When it did not work I replaced the battery with one I just bought a week or so ago. I then put in a debug for the noteLetter and the noteFreq. The breadboard has a piezo speaker hooked up to PIN 8 and ground. Even though the "P" has four zero's after it it still makes a sound. Here's my code. Will somebody tell me how to make a code box? This one did not work out too well!
Thanks Casey
' {$STAMP BS2} ' {$PBASIC 2.5} ' Bet with pause Notes DATA "G","G","G","e","P","F","F","F","D","Q" Durations DATA 8, 8, 8, 2, 8, 8, 8, 8, 2 WholeNote CON 2000 index VAR Byte offset VAR Nib noteLetter VAR Byte noteFreq VAR Word noteDuration VAR Word DO UNTIL noteLetter = "Q" READ Notes + index, noteLetter LOOKDOWN noteLetter, [ "A", "b", "B", "C", "d", "D", "e", "E", "F", "g", "G", "a", "P", "Q" ], offset DEBUG " ", noteLetter LOOKUP offset, [ 1760, 1865, 1976, 2093, 2217, 2349, 2489, 2637, 2794, 2960, 3136, 3322, 0, 0 ], noteFreq DEBUG " ", DEC4 noteFreq READ Durations + index, noteDuration noteDuration = WholeNote / noteDuration FREQOUT 8, noteDuration, noteFreq index = index + 1 LOOP END
Thanks Casey
Comments
Unfortunately in this instance the "P" is still a note. You can change the duration of the "P" since it is considered a note and increase the pause to the duration of a normally played note. However, since all note durations are fractions of a whole note value, and you cannot individually specify whole note values for each note, you are limited on the length of your pause. You can add P's into your code, but I found that you still get the chirp from the speaker that you mentioned. Hopefully this helps!