Quantcast
Channel: MEL PICBASIC Forum
Viewing all articles
Browse latest Browse all 4794

Take this action when these numbers are reached. How?

$
0
0
Is there a way to select an action when a specific number is reached in a counter?

For example, if I write:
Code:

counter = 0

loophere:
 if counter = 21 then counter = 0

counter = counter + 1

pause 100

goto loophere

What I would like to do is along the lines of:

if counter = 2 or 4 or 6 or 8 or 10 then
led1 = 1
else
led1 = 0
endif

if counter = 12 or 14 or 16 or 18 or 20 then
led2 = 1
else
led2 = 0
endif

I know you can write individual lines such as:

if (counter = 2) OR (counter = 4) OR (counter = 6)...then

or

if counter = 2 then
led1 = 1
else
led1 = 0
endif

if counter = 4 then
led1 = 1
else
led1 = 0
endif


And so on, but that eats up too much space. Just looking for someone to point me in the right direction. It's late and I'm drawing a blank as to which method to use to save space, but still get it done.

Thanks,
Tony

Viewing all articles
Browse latest Browse all 4794

Latest Images

Trending Articles



Latest Images