Shop OBEX P1 Docs P2 Docs Learn Events
Incrementing outputs — Parallax Forums

Incrementing outputs

ArchiverArchiver Posts: 46,084
edited 2003-11-06 00:04 in General Discussion
Hi,

I have a few outputs with LEDs connected to them, and I would like to
be able to set the LEDs to every possible state of being on or off by
incrementing a 4 bit counter. This way I can have a visual
representation of what phase my BS2SX program is in.

I have 4 LED's and I want the lights to all be off first
0 0 0 0
Then I want to increment the lights by one
0 0 0 1
and again
0 0 1 0
and again
0 0 1 1
and so on until I get to the highest incremented value (16) which is
1 1 1 1

I know there must be a slick way to do this. Can somebody tell me
what it is?

Thanks,
/John

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2003-11-06 00:04
    The BASIC Stamp make this a BREEZE! Assuming you have a BS2....

    ' {$STAMP BS2}

    Leds VAR OUTA ' Leds on P0 - P3; active high

    Setup:
    DIRA = %1111 ' make pins outputs

    Test:
    Leds = Leds + 1 ' increment LEDs value
    PAUSE 1000 ' 1 second to view
    GOTO Test ' loop forever


    This works because the PIC/SX architecture allows us to treat IO pins
    like variables, and the Stamp very cleverly defines pins individually
    and in groups. I will let you read the manual (hint, hint) to figure
    out how the program works.

    -- Jon Williams
    -- Applications Engineer, Parallax
    -- Dallas Office



    Original Message
    From: John Schwab [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=3xD1jQw8HI2wEsA5_T6UkVtHge4PDHorYS6yHM3C0HWgSns3xO2xIyj_LXVBtu2EeMMJ0jwU7_9F6IIVplk]johnschwab5678@y...[/url
    Sent: Wednesday, November 05, 2003 5:33 PM
    To: basicstamps@yahoogroups.com
    Subject: [noparse][[/noparse]basicstamps] Incrementing outputs


    Hi,

    I have a few outputs with LEDs connected to them, and I would like to
    be able to set the LEDs to every possible state of being on or off by
    incrementing a 4 bit counter. This way I can have a visual
    representation of what phase my BS2SX program is in.

    I have 4 LED's and I want the lights to all be off first
    0 0 0 0
    Then I want to increment the lights by one
    0 0 0 1
    and again
    0 0 1 0
    and again
    0 0 1 1
    and so on until I get to the highest incremented value (16) which is 1 1
    1 1

    I know there must be a slick way to do this. Can somebody tell me
    what it is?

    Thanks,
    /John



    To UNSUBSCRIBE, just send mail to:
    basicstamps-unsubscribe@yahoogroups.com
    from the same email address that you subscribed. Text in the Subject
    and Body of the message will be ignored.


    Your use of Yahoo! Groups is subject to
    http://docs.yahoo.com/info/terms/




    This message has been scanned by WebShield. Please report SPAM to
    abuse@p....
Sign In or Register to comment.