Stamp Demo Code
STAMP DEMO PROGRAMS
W. Durfee Mar-00
'----------------------------------------------------------
' demo1.bas
' Shows overflow on 8-bit variables.
'----------------------------------------------------------
b0 = 100
b0 = b0*3
debug b0
end
'----------------------------------------------------------
' demo1a.bas
' Shows overflow on 8-bit variables.
'----------------------------------------------------------
b0 = 250
w1 = 250
b1 = 4
loop:
b0 = b0+1
w1 = w1+1
b1 = b1-1
debug b0,w1,b1
pause 1000
goto loop
'----------------------------------------------------------
' demo2.bas
' Flashes output.
' Light is on pin 2.
'----------------------------------------------------------
loop:
high 2
pause 1000
low 2
pause 1000
goto loop
'----------------------------------------------------------
' demo2a.bas
' Flashes output. Shows use of SYMBOL
' Light is on pin 2.
'----------------------------------------------------------
symbol lamp = 2
symbol period = 1000
loop:
high lamp
pause period
low lamp
pause period
goto loop
'----------------------------------------------------------
' demo3.bas
' Flashes output using TOGGLE command
' Light is on pin 2.
'----------------------------------------------------------
symbol lamp = 2
symbol period = 1000
loop:
toggle lamp
pause period
goto loop
'----------------------------------------------------------
' demo4.bas
' Reading switch value via debug
' Switch is on pin 4
'----------------------------------------------------------
dirs = %11101111 ' set pin 4 as input
loop:
b0 = in4
debug b0
pause 500
goto loop
'----------------------------------------------------------
' demo5.bas
' Turns output on and off on switch closure.
' Uses IF statement to check switch.
' Light is on pin 2, switch is on pin 4
'----------------------------------------------------------
symbol lamp = 2
loop1:
if in4 = 1 then loop1 ' check switch
high lamp
pause 500 ' time to let go of switch
loop2:
if in4 = 1 then loop2 ' check switch again
low lamp
goto loop1
'----------------------------------------------------------
' demo6.bas
' Turns output on and off on switch closure.
' Shows use of BUTTON command.
' Light is on pin 2, switch is on pin 4
'----------------------------------------------------------
symbol lamp = 2
loop1:
button 4,0,255,0,b2,0,loop1 ' check switch
high lamp
loop2:
button 4,0,255,0,b2,0,loop2 ' check switch again
low lamp
goto loop1
'--------------------------------------------------------
' demo.bas
'
' Stamp demo program. 4-28-96 (wkd)
' Runs motor/leds/spkr, has switch (Stamp 1 code)
'--------------------------------------------------------
start:
b2 = 0 ' for button command
b4 = 100 ' sound variables
b5 = 80
top:
high 0 ' red led on
loop1: ' check switch
button 4,0,255,0,b2,0,loop1
action:
for b3 = 1 to 5
high 0 ' red led on
low 1 ' green led off
pause 500 ' wait 0.5 sec
low 0 ' red led off
high 1 ' green led on
pause 500
next b3
low 0 ' both led's off
low 1
pause 500
music:
sound 2,(b4,20,b4,20,b4,20,b5,100)
pause 250
for b3 = 0 to 127 step 10
sound 2,(25,10,b3,10)
next b3
pause 500
motor:
high 3 ' motor on
pause 2000 ' wait 2 sec
low 3 ' motor off
pause 750
finish:
sound 2,(120,75,50,75,120,150)
goto top ' start all over again