Newbie help. RGB Led on a PIC10F202


Closed Thread
Results 1 to 40 of 42

Hybrid View

  1. #1
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default Re: Newbie help. RGB Led on a PIC10F202

    Probably just a really bad case of switch bounce. Try adjusting the delay something like this;

    Code:
         WHILE !SwitchPin
            PAUSE 50  ' adjust this until it starts acting right. 
         WEND
    That might do it. If not place this same code at the bottom just before it returns to Main.

    You could also increment a variable in the WHILE loop. When it reaches a certain value it will indicate approx how long the switch was held down.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  2. #2
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default Re: Newbie help. RGB Led on a PIC10F202

    In Steve's code, PWM command should be in the main loop.
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  3. #3
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default Re: Newbie help. RGB Led on a PIC10F202

    ..........huh?
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  4. #4


    Did you find this post helpful? Yes | No

    Default Re: Newbie help. RGB Led on a PIC10F202

    Just curious, but what is the meaning of the exclamation point notation?
    WHILE !SwitchPin

  5. #5
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default Re: Newbie help. RGB Led on a PIC10F202

    That's an easy way to check if the value is 0. It means if switch is not 1.....
    Alternately, if switch means if switch =1 then. ....
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  6. #6
    Join Date
    Aug 2011
    Posts
    16


    Did you find this post helpful? Yes | No

    Default Re: Newbie help. RGB Led on a PIC10F202

    Well guys, things are working great so i more than thank you all for your wonderful help. This has been an experience for me and will continue to be as I convert all the code for this 10f202 to a 16f684. I wanted the EEPROM to store the state of the color after every change of color (after 10 seconds of on the same color so as to prevent excessive writes), so when the circuit comes back on again, it will grab the value from EEPROM. I also wanted the hardware PWM to control the LED color.

  7. #7
    Join Date
    Aug 2011
    Posts
    16


    Did you find this post helpful? Yes | No

    Default Re: Newbie help. RGB Led on a PIC10F202

    I think for the most part i have been able to successfully port it, except that the SwitchPin does not work properly on the 16F684. My code is below:

    Code:
    SwitchPin var PORTA.2  ' Active low
     
    RD CON %00010010  ' red
    GR CON %00110000  ' green
    BL CON %00100010  ' blue
    YL CON GR & RD      ' green + red = yellow
    CY CON GR & BL      ' green + blue = cyan
    PR CON BL & RD      ' blue + red = purple
    WT CON GR & BL & RD   ' green + blue + red = white
    OF con %11111111  ' all LEDs off
     
    ButtonCount VAR BYTE
    ButtonCount = 0
    
    PORTC = %00111010    ' LEDs off 
    TRISC = %00000010  ' PC2: Input, other pin: Output 
     
    MAIN:
      IF !SwitchPin THEN
         WHILE !SwitchPin
            pAUSE 200
         wend
         ButtonCount = ButtonCount + 1
     
         SELECT CASE ButtonCount
           CASE 1 
             PORTC = RD
           CASE 2 
             PORTC = GR
           CASE 3 
             PORTC = BL 
           CASE 4
             PORTC = YL 
           case 5
             PORTC = CY
           case 6
             PORTC = PR
           case 7
             PORTC = WT
           case IS > 7
             PORTC = OF
             ButtonCount = 0
         END SELECT
     
      ENDIF
      GOTO MAIN
      END
    I hope its something simple like my TRIS or PORT registers. Thanks much.

Members who have read this thread : 1

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