How can I get input from a switch, ON/OFF, and use that to either enter a loop or exit a loop?
Printable View
How can I get input from a switch, ON/OFF, and use that to either enter a loop or exit a loop?
Give this a try
Code:switch var PortB.0
main:
if switch = 1 then loop ' enter the loop
' do some thing here . . .
goto main
loop:
if switch = 0 then main ' exit the loop
. . . loop code does something . . .
goto loop
Code:WHILE Switch=1
'put some code here
WEND
If I want switch to be linked to a pin, then how do I declare it before a loop to be an input?
Is this code done for the PICBASIC assembly or a version of BASIC as the name implies?
I did not see the first line, sorry, please disregard
Can someone read below, I was told to do this and I am still getting the errors below the code, What am I doing wrong still?
Thank you in advance.
code below:
---------------
switch var PortB.0
main:
if switch =1 then loop 'enter loop
'forward
high PORTB.7 'enable pin
high PORTB.6
low PORTB.5
high PORTB.4
low PORTB.3
high PORTB.2 'enable pin
goto main
loop:
if switch=0 then main 'exit the loop
'backup
high PORTB.7 'enable pin
low PORTB.6 'stop this side
low PORTB.5
low PORTB.4 'reverse this side
high PORTB.3
high PORTB.2 'enable pin
goto loop
-------------------------------------
errors recieved below:
ERROR Line 13: ':' or '=' Expected (Token 'var') (Loop test2.pbc)
ERROR Line 13: Illegal Character '.' (Loop test2.pbc)
ERROR Line 17: Variable Expected (Token 'switch') (Loop test2.pbc)
ERROR Line 19: Variable or Constant Expected (Token 'PORTB') (Loop test2.pbc)
ERROR Line 19: Illegal Character '.' (Loop test2.pbc)
ERROR Line 20: Variable or Constant Expected (Token 'PORTB') (Loop test2.pbc)
ERROR Line 20: Illegal Character '.' (Loop test2.pbc)
ERROR Line 21: Variable or Constant Expected (Token 'PORTB') (Loop test2.pbc)
ERROR Line 21: Illegal Character '.' (Loop test2.pbc)
ERROR Line 23: Variable or Constant Expected (Token 'PORTB') (Loop test2.pbc)
ERROR Line 23: Illegal Character '.' (Loop test2.pbc)
ERROR Line 24: Variable or Constant Expected (Token 'PORTB') (Loop test2.pbc)
ERROR Line 24: Illegal Character '.' (Loop test2.pbc)
ERROR Line 25: Variable or Constant Expected (Token 'PORTB') (Loop test2.pbc)
ERROR Line 25: Illegal Character '.' (Loop test2.pbc)
ERROR Line 30: Variable Expected (Token 'switch') (Loop test2.pbc)
ERROR Line 32: Variable or Constant Expected (Token 'PORTB') (Loop test2.pbc)
ERROR Line 32: Illegal Character '.' (Loop test2.pbc)
ERROR Line 33: Variable or Constant Expected (Token 'PORTB') (Loop test2.pbc)
ERROR Line 33: Illegal Character '.' (Loop test2.pbc)
ERROR Line 34: Variable or Constant Expected (Token 'PORTB') (Loop test2.pbc)
ERROR Line 34: Illegal Character '.' (Loop test2.pbc)
ERROR Line 36: Variable or Constant Expected (Token 'PORTB') (Loop test2.pbc)
ERROR Line 36: Illegal Character '.' (Loop test2.pbc)
ERROR Line 37: Variable or Constant Expected (Token 'PORTB') (Loop test2.pbc)
ERROR Line 37: Illegal Character '.' (Loop test2.pbc)
ERROR Line 38: Variable or Constant Expected (Token 'PORTB') (Loop test2.pbc)
ERROR Line 38: Illegal Character '.' (Loop test2.pbc)
--------------------------------------
:eek: By seeing the .pbc extension, I'm I right by saying you have PBC not PBP?
If so... well.. both are WAY different... PBC don't allow direct addressing to a byte/register bit, and so forth for many other command as well.
Who have PBC here?
try this
Finger crossed, I don't have PBCCode:SYMBOL PORTB=$06
symbol TRISB=$86
POKE TRISB,1 ' PORTB.0 = input, other = output
POKE PORTB,0 ' Clear all output
main:
PEEK PORTB,B0
if BIT0 =1 then goto loop 'enter loop
'forward
high 7 'enable pin
high 6
low 5
high 4
low 3
high 2 'enable pin
goto main
loop:
PEEK PORTB,B0
if BIT0=0 then GOTO main 'exit the loop
'backup
high 7 'enable pin
low 6 'stop this side
low 5
low 4 'reverse this side
high 3
high 2 'enable pin
goto loop
What is the difference of PBC?
How can I get what you have?
Hi,
here's comparision between PBC (PicBasic) and PBP (picBasic Pro)
http://melabs.com/products/comp_pro.htm
Depending where you're living, you can purchase it from the following one
http://melabs.com/purchase.htm#Distributors
You can also download a limited demo version of PBP.
http://melabs.com/pbpdemo.htm