Help ASAP
george17
Posts: 3
im working on a project ...its nothing big but i need help with the coding.After the first part is done(gosubturn) i want to be able to press the button IN3 in order to go to supermario
Below is my code;
' {$STAMP BS2}
' {$PBASIC 2.5}
duration VAR Word
frequency VAR Word
PAUSE 1000
DEBUG "Alarm...", CR
PAUSE 100
FREQOUT 8, 500, 1500
PAUSE 500
FREQOUT 8 , 500, 1500
PAUSE 500
FREQOUT 8 , 500, 1500
PAUSE 500
FREQOUT 8, 500, 1500
PAUSE 1000
DEBUG "Alarm...", CR
PAUSE 100
FREQOUT 8, 500, 1500
PAUSE 500
FREQOUT 8 , 500, 1500
PAUSE 500
FREQOUT 8 , 500, 1500
PAUSE 500
FREQOUT 8, 500, 1500
PAUSE 1000
DEBUG "Robot reply...", CR
PAUSE 1000
FREQOUT 8, 100, 2800
FREQOUT 8, 200, 2400
FREQOUT 8, 140, 4200
FREQOUT 8, 30, 2000
PAUSE 500
GOSUB turn
PAUSE 1000
ENDIF (IN3=1)
supermario:
SpeakerPin CON 4
counter VAR Word
char VAR Byte
index VAR Word
noteLetter VAR Byte
noteFreq VAR Word
noteOctave VAR Word
tempo VAR Word
default_d VAR Byte
default_o VAR Byte
default_b VAR Word
RTTTL_File DATA "smb:d=4,o=5,b=100:16e6,16e6,32p,8e6,16c6,8e6,8g6,8p,8g,8p,8c6,16p,8g,16p,8e,16p,8a,8b,16a#,8a,16g.,16e6,16g6,8a6,16f6,8g6,8e6,16c6,16d6,8b,16p,8c6,16p,8g,16p,8e,16p,8a,8b,16a#,8a,16g.,16e6,16g6,8a6,16f6,8g6,8e6,16c6,16d6,8b,8p,16g6,16f#6,16f6,16d#6,16p,16e6,16p,16g#,16a,16c6,16p,16a,16c6,16d6,8p,16g6,16f#6,16f6,16d#6,16p,16e6,16p,16c7,16p,16c7,16c7,p,16g6,16f#6,16f6,16d#6,16p,16e6,16p,16g#,16a,16c6,16p,16a,16c6,16d6,8p,16d#6,8p,16d6,8p,16c6"
Done DATA ",q,"
Notes DATA "p", "a", "#", "b",
"c", "#", "d", "#",
"e", "f", "#", "g",
"#"
Octave8 DATA Word 0, Word 3520, Word 3729, Word 3951,
Word 4186, Word 4435, Word 4699, Word 4978,
Word 5274, Word 5588, Word 5920, Word 6272,
Word 6645
counter = 0
GOSUB FindEquals
GOSUB ProcessDuration
GOSUB FindEquals
GOSUB ProcessOctave
GOSUB FindEquals
GOSUB GetTempo
DO UNTIL char = "q"
GOSUB ProcessDuration
GOSUB ProcessNote
GOSUB CheckForDot
GOSUB ProcessOctave
GOSUB PlayNote
LOOP
END
FindEquals:
DO
READ RTTTL_File + counter, char
counter = counter + 1
LOOP UNTIL char = "="
RETURN
GetTempo:
default_b = 0
DO
READ RTTTL_File + counter, char
IF char = ":" THEN
default_b = default_b / 10
counter = counter + 1
EXIT
ENDIF
default_b = default_b + char - 48
counter = counter + 1
default_b = default_b * 10
LOOP UNTIL char = ":"
RETURN
ProcessOctave:
READ RTTTL_File + counter, char
SELECT char
CASE "5" TO "8"
noteOctave = char - "0"
counter = counter + 1
CASE ELSE
noteOctave = default_o
ENDSELECT
IF default_o = 0 THEN
default_o = noteOctave
ENDIF .
RETURN
READ RTTTL_File + counter, char
SELECT char
CASE "p"
index = 0
counter = counter + 1
CASE "a" TO "g"
FOR index = 1 TO 12
READ Notes + index, noteLetter
IF noteLetter = char THEN EXIT
NEXT
counter = counter + 1
READ RTTTL_File + counter, char
SELECT char
CASE "#"
index = index + 1
counter = counter + 1
ENDSELECT
ENDSELECT
RETURN
ProcessDuration:
READ RTTTL_File + counter, char
SELECT char
CASE "1", "2", "3", "4", "8"
duration = char - 48
counter = counter + 1
READ RTTTL_File + counter, char
SELECT char
CASE "6", "2"
duration = duration * 10 + char - 48
counter = counter + 1
ENDSELECT
CASE ELSE
duration = default_d
ENDSELECT
IF default_d <> 0 THEN
duration = 60000/default_b/duration*3
ELSE
default_d = duration
ENDIF
RETURN
CheckForDot:
READ RTTTL_File + counter, char
SELECT char
CASE "."
duration = duration * 3 / 2
counter = counter + 1
ENDSELECT
RETURN
PlayNote:
READ RTTTL_File + counter, char
SELECT char
CASE ","
counter = counter + 1
READ Octave8 + (index * 2), Word noteFreq
noteOctave = 8 - noteOctave
noteFreq = noteFreq / (DCD noteOctave)
IF noteFreq = 0 THEN
PAUSE duration
ELSE
FREQOUT 8, Duration,notefreq
ENDIF
ENDSELECT
RETURN
turn:
FOR counter = 1 TO 15
PULSOUT 14, 7500
PAUSE 200
NEXT
Below is my code;
' {$STAMP BS2}
' {$PBASIC 2.5}
duration VAR Word
frequency VAR Word
PAUSE 1000
DEBUG "Alarm...", CR
PAUSE 100
FREQOUT 8, 500, 1500
PAUSE 500
FREQOUT 8 , 500, 1500
PAUSE 500
FREQOUT 8 , 500, 1500
PAUSE 500
FREQOUT 8, 500, 1500
PAUSE 1000
DEBUG "Alarm...", CR
PAUSE 100
FREQOUT 8, 500, 1500
PAUSE 500
FREQOUT 8 , 500, 1500
PAUSE 500
FREQOUT 8 , 500, 1500
PAUSE 500
FREQOUT 8, 500, 1500
PAUSE 1000
DEBUG "Robot reply...", CR
PAUSE 1000
FREQOUT 8, 100, 2800
FREQOUT 8, 200, 2400
FREQOUT 8, 140, 4200
FREQOUT 8, 30, 2000
PAUSE 500
GOSUB turn
PAUSE 1000
ENDIF (IN3=1)
supermario:
SpeakerPin CON 4
counter VAR Word
char VAR Byte
index VAR Word
noteLetter VAR Byte
noteFreq VAR Word
noteOctave VAR Word
tempo VAR Word
default_d VAR Byte
default_o VAR Byte
default_b VAR Word
RTTTL_File DATA "smb:d=4,o=5,b=100:16e6,16e6,32p,8e6,16c6,8e6,8g6,8p,8g,8p,8c6,16p,8g,16p,8e,16p,8a,8b,16a#,8a,16g.,16e6,16g6,8a6,16f6,8g6,8e6,16c6,16d6,8b,16p,8c6,16p,8g,16p,8e,16p,8a,8b,16a#,8a,16g.,16e6,16g6,8a6,16f6,8g6,8e6,16c6,16d6,8b,8p,16g6,16f#6,16f6,16d#6,16p,16e6,16p,16g#,16a,16c6,16p,16a,16c6,16d6,8p,16g6,16f#6,16f6,16d#6,16p,16e6,16p,16c7,16p,16c7,16c7,p,16g6,16f#6,16f6,16d#6,16p,16e6,16p,16g#,16a,16c6,16p,16a,16c6,16d6,8p,16d#6,8p,16d6,8p,16c6"
Done DATA ",q,"
Notes DATA "p", "a", "#", "b",
"c", "#", "d", "#",
"e", "f", "#", "g",
"#"
Octave8 DATA Word 0, Word 3520, Word 3729, Word 3951,
Word 4186, Word 4435, Word 4699, Word 4978,
Word 5274, Word 5588, Word 5920, Word 6272,
Word 6645
counter = 0
GOSUB FindEquals
GOSUB ProcessDuration
GOSUB FindEquals
GOSUB ProcessOctave
GOSUB FindEquals
GOSUB GetTempo
DO UNTIL char = "q"
GOSUB ProcessDuration
GOSUB ProcessNote
GOSUB CheckForDot
GOSUB ProcessOctave
GOSUB PlayNote
LOOP
END
FindEquals:
DO
READ RTTTL_File + counter, char
counter = counter + 1
LOOP UNTIL char = "="
RETURN
GetTempo:
default_b = 0
DO
READ RTTTL_File + counter, char
IF char = ":" THEN
default_b = default_b / 10
counter = counter + 1
EXIT
ENDIF
default_b = default_b + char - 48
counter = counter + 1
default_b = default_b * 10
LOOP UNTIL char = ":"
RETURN
ProcessOctave:
READ RTTTL_File + counter, char
SELECT char
CASE "5" TO "8"
noteOctave = char - "0"
counter = counter + 1
CASE ELSE
noteOctave = default_o
ENDSELECT
IF default_o = 0 THEN
default_o = noteOctave
ENDIF .
RETURN
READ RTTTL_File + counter, char
SELECT char
CASE "p"
index = 0
counter = counter + 1
CASE "a" TO "g"
FOR index = 1 TO 12
READ Notes + index, noteLetter
IF noteLetter = char THEN EXIT
NEXT
counter = counter + 1
READ RTTTL_File + counter, char
SELECT char
CASE "#"
index = index + 1
counter = counter + 1
ENDSELECT
ENDSELECT
RETURN
ProcessDuration:
READ RTTTL_File + counter, char
SELECT char
CASE "1", "2", "3", "4", "8"
duration = char - 48
counter = counter + 1
READ RTTTL_File + counter, char
SELECT char
CASE "6", "2"
duration = duration * 10 + char - 48
counter = counter + 1
ENDSELECT
CASE ELSE
duration = default_d
ENDSELECT
IF default_d <> 0 THEN
duration = 60000/default_b/duration*3
ELSE
default_d = duration
ENDIF
RETURN
CheckForDot:
READ RTTTL_File + counter, char
SELECT char
CASE "."
duration = duration * 3 / 2
counter = counter + 1
ENDSELECT
RETURN
PlayNote:
READ RTTTL_File + counter, char
SELECT char
CASE ","
counter = counter + 1
READ Octave8 + (index * 2), Word noteFreq
noteOctave = 8 - noteOctave
noteFreq = noteFreq / (DCD noteOctave)
IF noteFreq = 0 THEN
PAUSE duration
ELSE
FREQOUT 8, Duration,notefreq
ENDIF
ENDSELECT
RETURN
turn:
FOR counter = 1 TO 15
PULSOUT 14, 7500
PAUSE 200
NEXT
Comments
Please edit your post. You might get the requested help a little more guickly.
-Phil