Shop OBEX P1 Docs P2 Docs Learn Events
Led Dimming — Parallax Forums

Led Dimming

Travis BestTravis Best Posts: 8
edited 2007-07-20 00:05 in General Discussion
I am dimming a led using the pwm command I also want to be able to change the led brightness using a button input which I have been able to do my only problem is when I push the button and run my command to brighten the led or dim it the led blinks is their anyway to run two command at once????


Thanks For Any Help
Travis

Comments

  • Sparks-R-FunSparks-R-Fun Posts: 388
    edited 2007-07-19 22:47
    Take a look at the PWM heading under the Best SX Threads Index sticky post. You should find some good ideas and examples there.

    - Sparks
  • Jared WoolstonJared Woolston Posts: 36
    edited 2007-07-19 23:07
    Its quite possible i am simply missunderstanding something you said but it sounds to me as if there is some part of your code which is deactivating the led for an excessive length of time....that being said, if there is nothing in the code you wrote that is doing this then look at what SX\B is doing. if i had to guess id say the delay is in the reinitializing of the PWM after the button press. since the pwm command in sx\b does not run at a fixed frequency (ive found other processor functions and duty cycle greatly influence its frequency), you are likely getting longer than desired relative off periods for the pwm. if the delay got worse as duty cycle went down, i would believe this to be the case. my fix then would be to use an interrupt running at a decent, constant speed and a counter to control if the pin is on or off. Guenther's book describes something like this which i think is what sparks referred you to. interrupts are not desired just use a simple polling loop routine to do the same thing.

    - Jared

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    A wise man who is not known for sure to have existed once said, "Never test a river with both feet." I feel this is especially true in engineering...throughout history everytime something new was tried with little research or planning, the odds were stacked in favor of failure, and everyone knows the house always wins in the long run....
  • JonnyMacJonnyMac Posts: 9,275
    edited 2007-07-20 00:05
    If want to control brightness of an LED with a button you could use an ISR to handle the PWM while the foreground takes care of button monitoring and level adjustment.
Sign In or Register to comment.