|
 |
Physical
Computing: Jen Lewin 2002
Step One: Setup a version of "Flashme" for your BX
Flashme is a very
simple startup function I wrote for my BX. "Flashme" is the
first things I run for every program I write on the BX. This helps by providing
useful startup information, that often saves me great time in debugging.
|
Sub Main()
call flashme(5)
'I place my new function (defined below)
flashme, as the first thing to run on the BX. This function passes the
number 2... in the function definition below... this number... will equal
my variable "flashX".
End
Sub
sub flashme(byVal flashx as byte)
'create a function called "flashme", with one passed byte variable
(passed by its value) called "flashX"
dim
x as byte 'create a byte variable (just
for inside this flashme function) called X
debug.print"RESTART" 'this
prints the text "RESTART" to the com window..Sometimes your
chip will turn off without your knowing it... the "restart" text, like the flash sequence below, is simply an indicator to let us
know when our chip may have been shutdown.
for x = 0 to flashx 'flash
pin 25 on and off flashX times...for example, if flashX = 5, it will flash
5 times
call
putpin(25, 0)
delay(0.1)
call
putpin(25, 1)
delay(0.1)
next
call
putpin(26, 0) 'once everything is finished,
turn pin 26 (the green 'go' pin on)
end sub
|
STEP TWO: Simple
Switches
|
Wire up a simple switch
to your BX pin 12.
Run the following script on your BX
sub Main()
do
debug.print"my pin 12 switch is ", cstr(getpin(12))
delay(0.2)
loop
end sub
|
Simple
Switch Schematic:

|
In your com port window, you should see the value of your switch( 1's for on,
0's for off.) Now imagine
your were creating a musical instrument where each time you push the switch
you want to hear a tone. In the above example, If you were to hold down the
switch, the tone would continue to play (in the com port you would be seeing
a 1 , 1, 1, 1 and in your instrument you would be hearing tone, tone, tone,
tone).
Most instruments,
and in general most switches do not work this way. When we pluck a string, it
resonates only once (until we pluck again). Likewise, most switches only "do
something" once when pushed, not continually while they are pushed.
In the below example, I have created a program that only "does something" (in this case, it only prints the value of the switch to the com window), one
time (for each switch press).
Write your own similar example (perhaps even as a separate function like "flashme" ).
|
'SET UP VARIABLES
dim
mySwitch as byte 'create a variable called mySwitch that is a byte
dim switchON as byte 'create a variable called switchON that is a byte
sub main()
call flashme(5) 'see
example above
'set
up the default values for my variables
mySwitch = 0
switchON = 0
DO
if getPin(12) = 1 then 'if
the switch is on....
if
switchON = 1 then 'then
if it is on, AND if it is being held down (if it was already pressed)
'do
nothing
else 'if
it is ON, but not already pressed
mySwitch
= mySwitch + 1 'add
1 to mySwitch
switchON
= 1 'set
switchON to be 1
debug.print
cStr(mySwitch)
'print the value of switchON
end
if
else 'Switch
is not on
switchON
= 0 'is if the switch is not on,
set the value of SwitchON to 0
end
if
loop
end sub
|
|