' IN_1.BAS (BASIC-X)
'
' Reads switch on pin P2. If at logic zero (ground), flashes LED on
' P14 three times. If at logic one (open), displays a string and flashes
' LED one time. Continually loops.
'
' Routine illustrates how to display a string, use of the sleep command,
' configuring a pin as either an input with internal pullup or as an
' active low or high and use of "if - else" and "for - next".
'
' Note improved "if" over the Parallax Basic Stamp.
'
' copyright, David Seebold and Crystal Fleet, Baltimore, MD, Sept, '99
Dim OCom(1 To 30) As Byte
Dim ICom(1 To 30) As Byte
Sub Main()
Const P2 as Byte = 2 ' input switch
Const P14 as Byte = 14 ' output LED
Dim i as Byte ' index
Dim str as String * 20 ' general string
Dim InputState as Byte
Call OpenQueue(OCom, 30)
Call OpenQueue(ICom, 30)
Call OpenCom(2, 9600, ICom, OCom)
Do ' continual loop
Call PutPin(P2, bxInputPullup)' configure P2 as an input with pullup
InputState = GetPin(P2) ' read P2
If (InputState = 0) Then ' if P2 is at ground
For i = 1 To 3 Step 1 ' flash LED on P14 three times
Call PutPin(P14, bxOutputHigh)
Call Sleep(0.1) ' about 100 ms
Call PutPin(P14,bxOutputLow)
Call Sleep(0.1)
Next
Call Sleep(3.0) ' wait for three seconds
Else
str = "Switch is Open" ' ouput a string
Call PutQueueStr(OCom, str)
Call PutQueueStr(OCom, Chr(13) & Chr(10)) ' new line
Call PutPin(P14, bxOutputHigh) ' then flash LED one time
Call Sleep(0.5) ' about 500 ms
Call PutPin(P14, bxOutputLow)
Call Sleep(3.0)
End If
Loop
End Sub