BasicMicroUK - Forums

www.basicmicro.co.uk
It is currently Mon Jul 16, 2018 1:38 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Pin variable names
PostPosted: Wed Feb 01, 2012 6:46 am 
Offline
Citizen

Joined: Wed Feb 01, 2012 5:57 am
Posts: 11
So can someone tell me why is the simple example below not work when I sub switch or lamp for in0 and P2 in the main code?
switch var bit
switch = in0
lamp var bit
lamp = out2

main:
if in0 then
low p2
else
high p2
endif
goto main


Top
 Profile  
 
 Post subject: Re: Pin variable names
PostPosted: Wed Feb 01, 2012 3:39 pm 
Offline
Master

Joined: Tue Nov 21, 2006 5:34 pm
Posts: 662
Since you defined switch and lamp as a bit variable, they will simply report what is in them or be set to what you set them to... For output things like lamp. That is easy. You should use the CON instead of defining them as variables...

But I don't think this works for input. There are some other hacks I have seen, using the LookUp command... Something like:

Code:
switch con 0
lamp con p2
switchval var bit

main:
  lookup switch, [in0, in1, in2, in3, in4, in5], switchval
  if switchval then
      low lamp
  else
    high lamp
  endif
goto main


Obviously this does not make sense to do in a fixed case, but this can be useful, if the switch pin is passed to a subroutine...

Kurt


Top
 Profile  
 
 Post subject: Re: Pin variable names
PostPosted: Wed Feb 01, 2012 10:18 pm 
Offline
Site Admin
User avatar

Joined: Thu Mar 01, 2001 7:00 pm
Posts: 1316
Location: Temecula, CA
The reason your code doesn't work is because you are only reading the input pin once at the begining of your program. By the time your code gets to the if statement the stae of the pin may have change. What you want is to read the current state of the pin which is what you are doing when you usin IN0 directly in the if statement.

You can alias a pin variable so you have something more readable like this.

Code:
switchval var in0

if switchval then
endif


This makes switchval point to the same thing as in0.

_________________
Tech Support
Basic Micro - Robotic Technology Evolved


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

phpBB SEO