The RETURN command on a PICAXE does not take any argument. It should just be RETURN, nothing following it.return playNote: ' codedNote has "TUNE" note encoding: %ddoonnnn: duration, octave, note (12-tone)
^
Syntax error on line 177 at/before position 20
Return
playNote:
Do
If pinC.0 = 1 Then
High B.0
Else
Low B.0
End If
Loop
Do
If pin0 = 1 Then
High 0
Else
Low 0
End If
Loop
if pin 0 = 1 then flsh ; jump to flsh if pin0 is high
poke 56,B.6,B.5,B.4,B.4,0 ' plus all the rest of the notes (put the trailing 0 at the end)
bptr=56 ' above top named variable
do : high @bptr : Do : Loop Until pinC.0 = 1 or pinC.1 = 1 : Pause 100 : low @bptrinc : loop until @bptr = 0
A simpler version of what lbenson presented using DATA and READ commands rather than POKE and bptr variables which might be easier to get your head around would be -The paragraph above is going to keep us busy for a day or two....
Data ( B.6, B.5, B.4, B.4 )
Data ( $FF )
b0 = 0
Read b0, b1
Do
High b1
Do : Loop Until pinC.0 = 1 or pinC.1 = 1
Pause 100
Low b1
b0 = b0 + 1
Read b0, b1
Loop Until b1 = $FF
Hippy's code is functionally the same as mine, except that he is storing the note B.# values in eeprom instead of ram.
You can see exactly what is happening if you simulate it and single-step through it.
READ B0,B1 means move the value of the eeprom location specified in B0 to B1.
He was wise to use $ff as a terminator rather than 0, since 0 is a valid pin number.
#picaxe 28x2
poke 56,B.6,B.5,B.4,B.4,$ff ' plus all the rest of the notes (put the trailing 0 at the end)
bptr=56 ' above top named variable
do : high @bptr : Do : Loop Until pinC.0 = 1 or pinC.1 = 1 : Pause 100 : low @bptrinc : loop until @bptr = $ff
' 28Twinkle
#picaxe 28x2
'poke 56,B.6,B.5,B.4,B.4,$ff ' plus all the rest of the notes (put the trailing 0 at the end)
symbol _D=B.0
symbol E=B.1
symbol Fs=B.2
symbol G=B.3
symbol _A=B.4
symbol _B=B.5
symbol Cs=B.6
symbol DD=B.7
' Twinkle, Twinkle, Little Star
poke 56,_D,_D,_A,_A,_B,_B,_A, G,G,Fs,Fs,E,E,_D, _A,_A,G,G,Fs,Fs,E, _A,G,G,Fs,Fs,E, _D,_D,_A,_A,_B,_B,_A, G,G,Fs,Fs,E,E,_D, $ff
bptr=56 ' above top named variable
do : high @bptr : Do : Loop Until pinC.0 = 1 or pinC.1 = 1 : Pause 100 : low @bptrinc : loop until @bptr = $ff
In the PE6 simulator with C.0 and C.1 off, start the simulation of the Twinkle program. Set the simulation speed to 200ms (lower right). Click C.0 or C.1 on and leave it on. You should see the appropriate pins light up.We can't seem to get LBenson's code to loop past the first LED......(in the simulator)
You can do it by brute force, putting a pause when the LED goes off -Running Hippy's code, we're not getting the LEDs to blink twice when we repeat a note.
How can we insert a pause between two notes that are alike?
Data ( B.6, B.5, B.4, B.4 )
Data ( $FF )
b0 = 0
Read b0, b1
Do
High b1
Do : Loop Until pinC.0 = 1 or pinC.1 = 1
Pause 100
Low b1
Pause 100
b0 = b0 + 1
Read b0, b1
Loop Until b1 = $FF
Data ( B.6, B.5, B.4, B.4 )
Data ( $FF )
b0 = 0
Read b0, b1
Do
High b1
Do : Loop Until pinC.0 = 1 or pinC.1 = 1
Pause 100
Low b1
b2 = b1
b0 = b0 + 1
Read b0, b1
If b1 <> $FF And b1 = b2 Then
Pause 100
End If
Loop Until b1 = $FF
Do you mean in the simulator, or attached to the hammer dulcimer? The code was just informed (I hope) guesswork--I'd be interested to know if it actually leads you to play the tune recognizably.yes it's working!
"<>" means either less than or greater than, or, more concisely, not equal."If b1 <> $FF And b1 = b2 Then"
what does <> mean in this line? more or less?
Great. (Now I wonder what other tunes use only the notes you now have available.)Yes, twinkle works in the simulator and plays on the dulcimer!