Shop OBEX P1 Docs P2 Docs Learn Events
Basic stamp 2 light dimmer — Parallax Forums

Basic stamp 2 light dimmer

Emery WaymanEmery Wayman Posts: 18
edited 2006-06-17 01:18 in BASIC Stamp
Need help programming Basic Stamp 2 to slowly stairstep light on to bright, then bright to off in a continuous loop.

Comments

  • Tristan TTristan T Posts: 31
    edited 2006-06-12 17:09
    Try using PULSOUT(page 347 in the PBASIC Reference) in a for loop, where you use your counter as a factor in the duration of the pulse.
    i.e.
    counter VAR Word
    
    for counter = 0 to 1000
         PULSOUT 0, counter
    next
    
    



    That should start the LED dimly and brighten it... play around with that and maybe a pause after the PULSOUT.

    -Tristan
  • Emery WaymanEmery Wayman Posts: 18
    edited 2006-06-12 18:24
    Hi Tristan, I'm really a newbe at this stamp thing. Any chance I could get you to write me a program for the stamp to do it? I would be happy to pay you for it.

    Emery
  • Tristan TTristan T Posts: 31
    edited 2006-06-12 18:32
    Emery,
    Is this for a class?
    -Tristan
  • Emery WaymanEmery Wayman Posts: 18
    edited 2006-06-12 20:11
    Tristan,
    No, not for a class. Actually I am working on light for color therapy that I want to experiment with.
    -Emery
  • Tristan TTristan T Posts: 31
    edited 2006-06-12 20:52
    Emery,
    This solution may not be suitable for color therapy as it causes the light to flicker, but if you have a basic stamp in front of you you can give this a try. I wired Pin14 to a 470ohm resistor to an led to Vss, and ran:
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    i VAR Word        ''declare i as a variable
    DO
      FOR i = 0 TO 100  ''count from 0 to 100
      HIGH 14           ''turn the LED on
      PAUSE 1+(i /10)   ''pause for 1 + (the counter divided by 10 (rounded down))ms
      LOW 14            ''turn the LED off
      PAUSE 10 - (i/10) ''keep the LED off for 10 ms
      NEXT
    
      HIGH 14           ''turn the LED all the way on for half a second
      PAUSE 500
    
      FOR i = 0 TO 100  ''count from 0 to 100
      HIGH 14           ''turn the LED on
      PAUSE (11 - (i/10))'leave it on for 11 - (the counter divided by 10)ms
      LOW 14            ''turn the LED off
      PAUSE 1 + i/10    ''leave it off for 10 ms
      NEXT
    
      LOW 14            ''leave the LED off for half a second
      PAUSE 500
    
    LOOP                ''and repeat forever
    



    The idea is that to dim the LED you simply have it off much longer than you have it on. So at the beginning of the loop when i = 0, you turn on the LED, pause for 1 millisecond and then turn it off for 10ms. Then it repeats this 9 more times before turning the LED on for 2ms and turning it off for 10.

    If this is not smooth enough you can get smaller pauses using a PULSOUT function, but give this a try first.
    If you have more questions about how to power LEDs using the BasicStamp, you might want to look at Chapter 2 of the "What is a Microcontroller" book here: www.parallax.com/dl/docs/books/edu/wamv2_2.pdf

    If the code above gives you the behavior that you are looking for I can help you edit it to have the LEDs behave to your specifications.

    (sorry about the student question, I'm happy to help anybody, but I didn't want to do somebody's homework or something.)

    -Tristan

    Post Edited (Tristan T) : 6/12/2006 9:02:07 PM GMT
  • Emery WaymanEmery Wayman Posts: 18
    edited 2006-06-12 21:43
    Hi Tristan,

    I do have a Basic Stamp in front of me but the problem is, my wife threw out my books and USB connecting cable and program out about 3 weeks ago. Now I have to order all new stuff to go on with my project. When I get it, I will instal the program that you sent and let you know if it works like I want it to. Thank you very much for taking the time to help me out.
    Question. The Stamp I have, has a program code on it that seems to work OK for what we are trying to do. When I get the new stuff, can I access the program that is already on my present Stamp with the Stamp editor?

    Emery
  • Tristan TTristan T Posts: 31
    edited 2006-06-12 22:32
    Emery,
    Sadly, the program stored on your stamp is gone once you reprogram it and there is (almost) no way to get it back. There is someone who at one point offered a program recovery service, but it required that you mail in your basic stamp and i'm sure wasn't cheap. Hopefully it won't be too hard to recreate.

    Once you have your basic stamp up and running again, feel free to post again, or private message me for any help.

    -Tristan
  • Ryan ClarkeRyan Clarke Posts: 738
    edited 2006-06-12 22:34
    And a side note- all of the Parallax books are available for free as PDF files from the Parallax website...

    Ryan

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Ryan Clarke
    Parallax Tech Support

    RClarke@Parallax.com
  • Emery WaymanEmery Wayman Posts: 18
    edited 2006-06-16 23:59
    Hi Tristan, I sent another e-mail to a different place on this forum but I don't know if you got it or not. What I said was that I got my basic stamp2 and program downloaded with the program you sent. It works like you said but I would like to lengthen the time that it takes to cycle from slow on to slow off. Can you help me with that? Thanks.
    Emery
  • Emery WaymanEmery Wayman Posts: 18
    edited 2006-06-17 01:18
    Hi Tristan,
    I tried the revision of the program that you sent. It doesn't work nearly as good as the original one you sent, so I downloaded the original program back to my BS2 and hooked it up to my DC Relay with 12 volts to a 12 vold light. The incandecent light goes on and off slow like the LED does but I can see the flicker and it cycles too fast. How and where would I use the PULSOUT command so it didn't flicker so much. Maybe we could just slow the cycle down a little less too. Thankyou much.
    Emery
Sign In or Register to comment.