LED blink program

When it comes to programming I’m not the best. I need help with a simple idea.

I can easily program the three color LEDs on the ABB (Pins 4-6) to turn on, pause for 50ms then turn off and each lead is turned on, then off one after the other to give a sorta light chasing effect. I want to write as few lines of code as possible to achive the same results which is where I need help. For one, How do you make the pin a variable that can be cycled between p4-p6?


; NOTE: "LOW" is ON and "HIGH" is OFF. It is backwards for these LEDs


top:

low p4
pause 50
high p4

lowp5
pause
high p5

low p6
pause 50
high p6

low p6
pause 50
high p6

low p5
pause 50
high p5

low p4
pause 50
high p4

goto top

I haven’t used basic in some time (and didn’t use it much to begin with), so I’m not sure if this is going to compile (I think this might work on an Atom, but possibly not a Parallax stamp).

[code]
blinkdir VAR sbyte
led VAR nib

led=4
blinkdir=1

top:
LOW led
PAUSE 50
HIGH led
led = led + blinkdir
IF led = 6 or led = 4 THEN
blinkdir = blinkdir * -1
ENDIF
GOTO top[/code]

try this :wink:

i var byte main for i = 4 to 6 low i pause 200 high i next goto main
for red - green - orange - red - green - orange …
or

i var byte main for i = 4 to 6 low i pause 200 high i next low 5 pause 200 high 5 goto main

for red - green - orange - green - red …

Thanks Matt, Laureatus!

You mean you do not need the “P” then the number? I thought Mbasic used P4 for pin 4, and I was thinking how do I split the P and the number and have it work.

yes, p4 is a constant, its value is…4 so use “low p4” or “low 4” or “low yourvariable” it will work.

i have modified my previous message to add another code

I learned something new to day. This is different than Pbasic where you simply use the PIN cmmand and then the variable for the pin number.

I ran your code and it works perfect.

I thought it would be neat to have this as a routine in certain parts of a program or when the bot is at idle or something.

Thanks! :smiley: