I have been doing the
exercises in the book and just can't resist changing them,
modifying them and just generally having fun with the learning
process... Here is a new program I made from the exercise in the
book on page 179... with a little twist I added some sounds to
the program to tell the difference between what mode it is in...
The file name I created is roaming_with_whiskers_R2D2.bs2
You can download the program source by right clicking the
link and choosing 'save target as' --- >>
roaming_with_whiskers_R2D2.bs2 <<< ---
It will be a text file, that you can rename as a .bs2 file
that the Basic Stamp Editor will load.
Roaming_with_whiskers_R2D2.bs2
-----------------------------------------------------------------------------cut
here
--------------------------------------------------------------
'Robotics with the BOE-BOT - roaming_with_whiskers_R2D2.bs2
'This program allows the BOE-BOT to travel and detect walls
'redirecting it self to escape with R2D2 like musical tones...
'this makes the interaction with obstacles much more
interesting!
' {$STAMP BS2}
' {$PBASIC 2.5}
DEBUG "Program Running!"
'---------[Variables]--------------------------------------------------
pulseCount VAR Byte 'For...Next Loop counter
'---------[Initialization]--------------------------------------------------
FREQOUT 4, 1000, 2000 'signal program start or reset
'---------[Main
routine]--------------------------------------------------
DO
IF (IN5 = 0) AND (IN7 = 0) THEN
GOSUB Beep1
GOSUB Back_Up
GOSUB Turn_Left
GOSUB Turn_Left
ELSEIF (IN5 = 0) THEN
GOSUB BEEP2
GOSUB Back_Up
GOSUB Turn_Right
ELSEIF (IN7 = 0) THEN
GOSUB Beep3
GOSUB Back_up
GOSUB Turn_Left
ELSE
GOSUB Forward_Pulse
ENDIF
LOOP
'---------[Subroutines]--------------------------------------------------
Forward_Pulse:
PULSOUT 13, 850
PULSOUT 12, 650
PAUSE 20
RETURN
Beep1:
'R2D2 says Na, na, na-na-na, na...
'A7
FREQOUT 4, 400, 3520
PAUSE 10
'F7
FREQOUT 4, 200, 2960
PAUSE 20
'G7
FREQOUT 4, 150, 3136
PAUSE 10
'B7
FREQOUT 4, 100, 3951
PAUSE 10
'A7
FREQOUT 4, 400, 3520
PAUSE 10
'F7
FREQOUT 4, 300, 2960
RETURN
Beep2:
'R2 - surprised sound
FREQOUT 4, 10, 2000
FREQOUT 4, 10, 2100
FREQOUT 4, 10, 2200
FREQOUT 4, 10, 2300
FREQOUT 4, 30, 2400
FREQOUT 4, 40, 2500
FREQOUT 4, 10, 3000
FREQOUT 4, 10, 3100
FREQOUT 4, 10, 3200
FREQOUT 4, 20, 3500
FREQOUT 4, 90, 3900
FREQOUT 4, 100, 4500
FREQOUT 4, 100, 4000
FREQOUT 4, 10, 3900
FREQOUT 4, 10, 2800
FREQOUT 4, 10, 2700
FREQOUT 4, 30, 2600
FREQOUT 4, 40, 2500
FREQOUT 4, 10, 2200
FREQOUT 4, 10, 2100
FREQOUT 4, 10, 2000
FREQOUT 4, 100, 1000
RETURN
Beep3:
'R2D2 musical scale
FREQOUT 4, 100, 3520
PAUSE 1
FREQOUT 4, 100, 3729
PAUSE 1
FREQOUT 4, 100, 3322
PAUSE 1
FREQOUT 4, 100, 3136
PAUSE 1
FREQOUT 4, 100, 3720
PAUSE 1
FREQOUT 4, 100, 3929
PAUSE 1
FREQOUT 4, 100, 3522
PAUSE 1
FREQOUT 4, 100, 3336
PAUSE 1
FREQOUT 4, 100, 3900
RETURN
Turn_Left:
FOR pulseCount = 0 TO 20
PULSOUT 13, 650
PULSOUT 12, 650
PAUSE 20
NEXT
RETURN
Turn_Right:
FOR pulseCount = 0 TO 20
PULSOUT 13, 850
PULSOUT 12, 850
PAUSE 20
NEXT
RETURN
Back_Up:
FOR pulseCount = 0 TO 40
PULSOUT 13, 650
PULSOUT 12, 850
PAUSE 20
NEXT
RETURN
-----------------------------------------------------------------------------cut
here
--------------------------------------------------------------