Shop OBEX P1 Docs P2 Docs Learn Events
LEDs and for...next — Parallax Forums

LEDs and for...next

ArchiverArchiver Posts: 46,084
edited 2001-04-03 04:25 in General Discussion
I'm a beginner (15 years old) with the Basic Stamp2 and I was wondering how
to get a LED, connected to pin 0, to light up when I push a button,
connected to pin 1.
I was also wondering how to get 10 LEDs, connected to pins 0 through 9, to
light up in sequence, but with four lit up at any one time. So LED numbers
0, 1, 2, and 3 are lit up in the start, then LED 3 goes off, 4 on, 4 off, 5
on, 5 off, and so on until all of the possible combinations of four have
been reached. How would I be able to do that without programming each
individual LED when to turn on and off?
Thanks.
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2001-04-01 03:05
    I'm a beginner (15 years old) with the Basic Stamp2 and I was
    wondering how to get a LED, connected to pin 0, to light up when I
    push a button, connected to pin 1.
    I was also wondering how to get 10 LEDs, connected to pins 0
    through 9, to light up in sequence, but with four lit up at any one
    time. So LED numbers 0, 1, 2, and 3 are lit up in the start, then LED
    3 goes off, 4 on, 4 off, 5 on, 5 off, and so on until all of the
    possible combinations of four have been reached. How would I be able
    to do that without programming each individual LED when to turn on
    and off?
    Thanks.
  • ArchiverArchiver Posts: 46,084
    edited 2001-04-01 04:16
    > I'm a beginner (15 years old) with the Basic Stamp2 and I was
    > wondering how to get a LED, connected to pin 0, to light up when I
    > push a button, connected to pin 1.

    'put a 4700 ohm resistor from pin1 to +5volts
    'put the switch from pin1 to ground (0 volts)
    'put the led and a 470 ohm resistor IN SERIES from pin 0 to ground

    start:
    if pin1 = 1 then ledoff
    pin0 = 1
    goto start
    ledoff:
    pin0=0
    goto start

    'hope this is some help
    'Chris

    > I was also wondering how to get 10 LEDs, connected to pins 0
    > through 9, to light up in sequence, but with four lit up at any one
    > time. So LED numbers 0, 1, 2, and 3 are lit up in the start, then LED
    > 3 goes off, 4 on, 4 off, 5 on, 5 off, and so on until all of the
    > possible combinations of four have been reached. How would I be able
    > to do that without programming each individual LED when to turn on
    > and off?

    'You could try this, putting a 470 ohm resistor and led between each i/o pin
    (from 0 to 9) and ground.
    counter var byte
    start:
    For counter = 0 to 9
    high counter
    pause 1000
    low counter
    goto start


    Original Message
    From: <sjohns10@h...>
    To: <basicstamps@yahoogroups.com>
    Sent: Sunday, April 01, 2001 10:05 AM
    Subject: [noparse][[/noparse]basicstamps] LEDs and for...next


    > I'm a beginner (15 years old) with the Basic Stamp2 and I was
    > wondering how to get a LED, connected to pin 0, to light up when I
    > push a button, connected to pin 1.
    > I was also wondering how to get 10 LEDs, connected to pins 0
    > through 9, to light up in sequence, but with four lit up at any one
    > time. So LED numbers 0, 1, 2, and 3 are lit up in the start, then LED
    > 3 goes off, 4 on, 4 off, 5 on, 5 off, and so on until all of the
    > possible combinations of four have been reached. How would I be able
    > to do that without programming each individual LED when to turn on
    > and off?
    > Thanks.
    >
    >
    >
    >
    > Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
    >
    >
  • ArchiverArchiver Posts: 46,084
    edited 2001-04-01 12:01
    [font=arial,helvetica]In a message dated 3/31/01 9:12:26 PM Central Daylight Time,
    sjohns10@hotmail.com writes:


    I'm a beginner (15 years old) with the Basic Stamp2 and I was
    wondering how to get a LED, connected to pin 0, to light up when I
    push a button, connected to pin 1.



    MyButton ····VAR ····In1
    MyLED ·······VAR ····Out0

    Initialize:
    ·Dir0 = 1 ················' make pin 0 an output

    Main:
    ·MyLED = MyButton
    ·GOTO Main

    This program assumes that you have a normally-open pushbutton between pin 1
    and +5. ·You must also connect a 10K resistor between pin 1 and ground. ·The
    resistor will hold the pin at 0 when the button is open.

    Connect the LED to pin 0. ·You need to limit the current with a resistor so
    the connection is something like this: Pin0 -- LED -- resistor -- ground.
    The resitor value can be anything from 220 ohms to 1K.


    ·I was also wondering how to get 10 LEDs, connected to pins 0
    through 9, to light up in sequence, but with four lit up at any one
    time. So LED numbers 0, 1, 2, and 3 are lit up in the start, then LED
    3 goes off, 4 on, 4 off, 5 on, 5 off, and so on until all of the
    possible combinations of four have been reached. How would I be able
    to do that without programming each individual LED when to turn on
    and off?



    Download my book, StampWorks, from the Parallax website (you can by from
    Parallax or from Amazon.com). ·The book will teach you Stamp 2 programming
    through 31 different experiments. ·One of the experiments is a lighting
    sequencer which will show you how to accomplish your second goal.

    -- Jon Williams
    -- Dallas, TX
    [/font]
  • ArchiverArchiver Posts: 46,084
    edited 2001-04-03 04:25
    Hi Seth:

    How about:

    OUTPUT 0
    top:
    out0=in1
    goto top

    Of course, if the LED is backwards with respect to the switch you could try:

    OUTPUT 0
    top:
    out0=in1^1 ' xor 1 will flip the in1 bit
    goto top


    As for the other, how about:

    mask var word
    dirs=%1111111111111111
    resetmask:
    mask = %0000000000001111
    again:
    outs=mask
    pause 500
    mask=mask<<1
    if mask=%0000111100000000 then resetmask ' (or whatever)
    goto again

    Once you have that, try making them reverse direction :-)

    Al Williams
    AWC
    * Microcontroller Projects with Basic Stamps:
    http://www.al-williams.com/awce/sbook.htm


    >
    Original Message
    > From: Seth Johnson [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=ePtmHcsaC7AWFGYxwE7Os0NNSvkH9svFsas1SAI7wyDr6RScyPSS94GuFfrUr9gzYSeZv0ebLhRxTAco5w]sjohns10@h...[/url
    > Sent: Saturday, March 31, 2001 8:02 PM
    > To: basicstamps@yahoogroups.com
    > Subject: [noparse][[/noparse]basicstamps] LEDs and for...next
    >
    >
    > I'm a beginner (15 years old) with the Basic Stamp2 and I was
    > wondering how
    > to get a LED, connected to pin 0, to light up when I push a button,
    > connected to pin 1.
    > I was also wondering how to get 10 LEDs, connected to pins 0
    > through 9, to
    > light up in sequence, but with four lit up at any one time. So
    > LED numbers
    > 0, 1, 2, and 3 are lit up in the start, then LED 3 goes off, 4
    > on, 4 off, 5
    > on, 5 off, and so on until all of the possible combinations of four have
    > been reached. How would I be able to do that without programming each
    > individual LED when to turn on and off?
    > Thanks.
    > _________________________________________________________________
    > Get your FREE download of MSN Explorer at http://explorer.msn.com
    >
    >
    >
    >
    > Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
    >
Sign In or Register to comment.