Results 1 to 5 of 5

Thread: Blink a LED with one line of active code

  1. #1
    Senior Member
    Join Date
    May 2011
    Location
    Atlanta, GA
    Posts
    775
    Blog Entries
    24

    Default Blink a LED with one line of active code

    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

  2. #2
    Senior Member
    Join Date
    Jan 2011
    Location
    UK
    Posts
    4,227
    Blog Entries
    12

    Default

    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.

  3. #3
    Senior Member
    Join Date
    May 2011
    Location
    Atlanta, GA
    Posts
    775
    Blog Entries
    24

    Default

    @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
    2-Purpose LED.jpg
    Last edited by mrburnette; 04-04-2012 at 13:43. Reason: graphic pointer

  4. #4
    Senior Member
    Join Date
    Jan 2011
    Location
    UK
    Posts
    4,227
    Blog Entries
    12

    Default

    Quote Originally Posted by mrburnette View Post
    See the configuration below...
    It seems that I can't!

  5. #5
    Senior Member
    Join Date
    May 2011
    Location
    Atlanta, GA
    Posts
    775
    Blog Entries
    24

    Default

    Quote Originally Posted by nick12ab View Post
    It seems that I can't!
    So, like when I click on Attachment 10926, I get a new page!

    2-Purpose LED.jpg

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •