Blink a LED with one line of active code

mrburnette

Senior Member
So often, it is necessary to just blink a LED on a pin to give us some satisfaction that something is going on inside that PICAXE chip. The perfect example is capturing a serial ASCII stream using SERIN with qualifiers/timeouts. What I see most PICAXE'rs doing is using a conditional statement (IF) and checking if a variable is 1 or 0 and then making the LED HIGH/LOW to toggle the state.

Due to the nature of the sink/source capability of many of PICAXE pins and the fact that most PICAXE pins can be bidirectional a very simple one-statement approach can be taken.

- Select a Pin that is bidirectional (not hardwired as input/output)
- If possible, select a pin that is both sink/source for output
- Code

Here is an example for the simulator. Sticking the REVERSE instruction anywhere in your code that is repetitively called will provide a simple, visual "I'm alive" signal to comfort the weary programmer. Use two pins for bi-colored LEDs! When using SERIN with a timeout and no "goto" option, place the 'reverse LED' statement after the SERIN command. With SERIN and a "goto", place the 'reverse LED' statement as the first statement after the LABEL. Be creative, the above are just suggestions.

Code:
#picaxe 18M2

Symbol LED = C.1
HIGH LED

Do
	REVERSE LED
	PAUSE 1000
Loop

- Ray
 

nick12ab

Senior Member
Why not use the toggle command? The reverse command switches a pin between input and output so wouldn't work with bi-colour LEDs which you've suggested.
 

mrburnette

Senior Member
@nick12ab: YES, that is the more normal way to do things.... I'm abbynormal (Fronkensteen), however. I used that approach in Magic Morse for the 08M2... if you want the PIN always to be an output.

I was playing around late Saturday night with a LED and and had never used the REVERSE command. I was (I thought) running short on pins and I found that I could multiplex the purpose of a PIN between running diags (LED enabled) and not running diags (LED and sertxd disabled.) Obviously, I did a very poor job of describing the whole concept in my post #1... In fact, I totally left that part out of the post as I hurried this morning before rushing out for an appointment. My bad.

See the configuration below... When jumper/switch S1 is open, reading C.1 during the initialization before the statement HIGH LED will give a "0" and means disable diagnostic blinking and a subroutine to send variables to sertxd. If jumper/switch S1 is closed, reading C.1 during the initialization will give a logic "1" (approximately 3.3V.) So, 1-pin, two functions.

- Ray

EDIT: reattached graphic
View attachment 10927
 
Last edited:
Top