User Selectable LED Brightness


Closed Thread
Results 1 to 7 of 7

Hybrid View

  1. #1
    Join Date
    Feb 2005
    Location
    Essex, UK
    Posts
    154


    Did you find this post helpful? Yes | No

    Default

    Thanks for that Ralph, i see where i went wrong on the increase.

    Having reached maximum brightness (255), how would i now make it decrease brightness back to 0. If i make it bright = bright - 1 then it only goes 1 step down, then back up again.

    I want it to perform like a conventional houshold light touch dimmer.

    Can you help, thanks.

    Steve

  2. #2
    Join Date
    Feb 2004
    Location
    Germany
    Posts
    762


    Did you find this post helpful? Yes | No

    Default

    Steve,

    There are many possible ways.

    Before I post a ready to run solution, I'll give you a hint that should help you to get started and let you do some homework.

    You could assign an extra variable (Flag VAR BIT) to memorize what the last action performed was: "increase" or "desrease" brightness.

    Dependend on FLAG you enter the decrease or increase loop when the button is pressed.

    Have you checked Presetting Configuration Fuses

    Let us know how you are getting on.
    regards

    Ralph

    _______________________________________________
    There are only 10 types of people:
    Those who understand binary, and those who don't ...
    _______________________________________________



  3. #3
    Join Date
    Feb 2005
    Location
    Essex, UK
    Posts
    154


    Did you find this post helpful? Yes | No

    Default

    Thank for the 'Hint', this is what i have come up with so far. I think i am along the right lines, but when you hit the button, it continously dims to OFF and there it stays. Am i on the right lines, before i go off on a tangent ?? Can you suggest anymore hints??

    Heres what i have:

    Code:
    TRISB = %10000001   ' Set PORTB (0)INPUT (1-5)OUTPUTS
    CMCON = 7 
    
    SecSwitch   VAR PORTA.5
    Red         VAR PORTB.1
    
    Bright      VAR Byte
    storedloop  VAR Byte
    
    flag VAR Byte
    
    bright = 254
    flag = 0
    Low red
    
    Main:
        If secswitch = 0 then gosub pwmroutine
    Goto Main
    
    
    PWMRoutine:
         While (Bright !=255) and (flag = 0)
              PWM red,Bright,5 
              bright = bright - 1
         Wend
         While (bright !=0) and (flag = 1)
              PWM red,Bright,5
              bright=bright + 1
         Wend
    Return
    
    Flash:
    For storedloop = 1 to 3
            High red
            Pause 100
            Low red
            Pause 100
    Next storedloop
    Return
    Cheers,

    Steve

  4. #4
    Join Date
    Feb 2004
    Location
    Germany
    Posts
    762


    Did you find this post helpful? Yes | No

    Default

    Steve,

    there is a number of things wrong now.
    in your main loop there will be no PWM output until you press the button.

    Once you have pressed the button it will execute the "decrease brighness" loop since flag=0
    (flag is always 0 in your case!!!)
    Since you don't check for "key still pressed?" in the While...Wend Loop
    it counts bright from 254 (preset value) down to zero.
    with the next decrement (down from zero) bright will be 255.

    From there on none of the conditions to output PWM
    is true or will ever become true. so nothing happens
    regards

    Ralph

    _______________________________________________
    There are only 10 types of people:
    Those who understand binary, and those who don't ...
    _______________________________________________



  5. #5
    Join Date
    Feb 2004
    Location
    Germany
    Posts
    762


    Did you find this post helpful? Yes | No

    Default

    Steve,

    regarding your PM,

    I think it has all been discussed alredy there
    regards

    Ralph

    _______________________________________________
    There are only 10 types of people:
    Those who understand binary, and those who don't ...
    _______________________________________________



Similar Threads

  1. Conway's Game Of Life
    By wellyboot in forum mel PIC BASIC Pro
    Replies: 45
    Last Post: - 28th May 2020, 06:14
  2. Free Project - 245 LED Display
    By T.Jackson in forum Code Examples
    Replies: 221
    Last Post: - 16th August 2009, 04:59
  3. new and need help
    By smeghead in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 3rd November 2008, 20:19
  4. LCD will not start
    By btaylor in forum mel PIC BASIC Pro
    Replies: 49
    Last Post: - 24th May 2007, 02:30
  5. can't even flash an LED
    By bruno333 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 28th April 2005, 13:27

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

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