Newbie help. RGB Led on a PIC10F202


Closed Thread
Results 1 to 40 of 42

Hybrid View

  1. #1
    Join Date
    Aug 2011
    Posts
    16

    Default Newbie help. RGB Led on a PIC10F202

    Hello all,

    I have a piece of code for PBP that i guess i need help with and am hoping someone will be able to point out the issue. Its a simple RGB LED circuit that when you push the button, should flip to the next color in a subroutine then at the end of the colors, go back to the start. Posting my code below, it may be the incorrect way to do it. It just sits on 'Red' as its the value for ButtonCount. I can change that value to 1,2,3 & compile/program and get ir to display the correct color, but it will not switch colors. Any suggestions will be much appreciated. Thanks in advance.


    Code:
    Red var GPIO.0
    Green var GPIO.1
    Blue var GPIO.2
    SwitchPin var GPIO.3
    
    ButtonCount VAR BYTE
    ButtonCount = 1
    
    ;Make sure LEDs are off
    HIGH Red 
    HIGH Green
    HIGH Blue
    
    MAIN:
    IF SwitchPin = 1 THEN ButtonCount = ButtonCount + 1
    GOTO SWITCHLOOP
    END
    
    SWITCHLOOP:
    If ButtonCount = 1 THEN GOSUB RedProgram
    If ButtonCount = 2 THEN GOSUB GreenProgram
    If ButtonCount = 3 THEN GOSUB BlueProgram
    If ButtonCount = 4 THEN ButtonCount = 1
    GOTO SWITCHLOOP
    END
    
    RedProgram:
    PWM Red,127,100
    RETURN
    
    GreenProgram:
    PWM Green,127,100
    RETURN
    
    BlueProgram:
    PWM Blue,127,100
    RETURN
    
    END

  2. #2
    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

    Once you enter switchloop, you seem to never leave
    -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!

  3. #3
    Join Date
    Aug 2011
    Posts
    16


    Did you find this post helpful? Yes | No

    Default Re: Newbie help. RGB Led on a PIC10F202

    Quote Originally Posted by cncmachineguy View Post
    Once you enter switchloop, you seem to never leave
    I put the IF statement that is in the MAIN portion into the SWITCHLOOP portion and same thing happens. Am I just doing it wrong altogether?

  4. #4
    Join Date
    Jan 2009
    Posts
    78


    Did you find this post helpful? Yes | No

    Default Re: Newbie help. RGB Led on a PIC10F202

    At the start up you going straight to the SWITCHLOOP routine, light up the red, then you never go back to the Main routine to check when SwitchPin became 1 (to increment the ButtonCount to change the color)
    Last edited by bogdan; - 14th August 2011 at 01:47.

  5. #5
    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

    Code:
            Red         var GPIO.0
            Green       var GPIO.1
            Blue        var GPIO.2
            SwitchPin   var GPIO.3
            
            ButtonCount VAR BYTE
            ButtonCount = 1
            
            ;Make sure LEDs are off
            HIGH Red 
            HIGH Green
            HIGH Blue
    
    MAIN:
            IF SwitchPin THEN 
                    If ButtonCount = 1 THEN GOSUB RedProgram
                    If ButtonCount = 2 THEN GOSUB GreenProgram
                    If ButtonCount = 3 THEN GOSUB BlueProgram
                    If ButtonCount = 4 THEN ButtonCount = 1
                    ButtonCount = ButtonCount + 1
                    endif
            GOTO MAIN
    
    RedProgram:
            PWM Red,127,100
            RETURN
    
    GreenProgram:
            PWM Green,127,100
            RETURN
    
    BlueProgram:
            PWM Blue,127,100
            RETURN
    Code:
            Red         var GPIO.0
            Green       var GPIO.1
            Blue        var GPIO.2
            SwitchPin   var GPIO.3
            
            ButtonCount VAR BYTE
            ButtonCount = 1
            
            ;Make sure LEDs are off
            HIGH Red 
            HIGH Green
            HIGH Blue
    
    MAIN:
            IF SwitchPin THEN 
                    If ButtonCount = 1 THEN 
                            PWM Red,127,100
                            ENDIF
                    If ButtonCount = 2 THEN 
                            PWM Green,127,100
                            ENDIF
                    If ButtonCount = 3 THEN 
                            PWM Blue,127,100
                            ENDIF
                    If ButtonCount = 4 THEN ButtonCount = 1
                    ButtonCount = ButtonCount + 1
                    endif
            GOTO MAIN
    Last edited by mister_e; - 14th August 2011 at 01:51.
    Steve

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

  6. #6
    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

    Code:
            Red         var GPIO.0
            Green       var GPIO.1
            Blue        var GPIO.2
            SwitchPin   var GPIO.3
            
            ButtonCount VAR BYTE
            ButtonCount = 0
            
            ;Make sure LEDs are off
            HIGH Red
            HIGH Green
            HIGH Blue
    
    MAIN:
            IF SwitchPin = 1 THEN
                    If ButtonCount<3 THEN
                            PWM GPIO.0(ButtonCount),127,100
                            ButtonCount = ButtonCount + 1
                        ELSE
                            ButtonCount = 0
                        ENDIF
                    endif
            GOTO MAIN
    Last edited by mister_e; - 14th August 2011 at 02:05.
    Steve

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

  7. #7
    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

    Mistake in my 2 first example. Change made in RED

    Code:
            Red         var GPIO.0
            Green       var GPIO.1
            Blue        var GPIO.2
            SwitchPin   var GPIO.3
            
            ButtonCount VAR BYTE
            ButtonCount = 1
            
            ;Make sure LEDs are off
            HIGH Red 
            HIGH Green
            HIGH Blue
    
    MAIN:
            IF SwitchPin THEN 
                    If ButtonCount = 1 THEN GOSUB RedProgram
                    If ButtonCount = 2 THEN GOSUB GreenProgram
                    If ButtonCount = 3 THEN GOSUB BlueProgram
                    If ButtonCount = 4 THEN 
                            ButtonCount = 1
                        else
                            ButtonCount = ButtonCount + 1
                        endif
                    endif
            GOTO MAIN
    
    RedProgram:
            PWM Red,127,100
            RETURN
    
    GreenProgram:
            PWM Green,127,100
            RETURN
    
    BlueProgram:
            PWM Blue,127,100
            RETURN
    Code:
            Red         var GPIO.0
            Green       var GPIO.1
            Blue        var GPIO.2
            SwitchPin   var GPIO.3
            
            ButtonCount VAR BYTE
            ButtonCount = 1
            
            ;Make sure LEDs are off
            HIGH Red 
            HIGH Green
            HIGH Blue
    
    MAIN:
            IF SwitchPin THEN 
                    If ButtonCount = 1 THEN 
                            PWM Red,127,100
                            ENDIF
                    If ButtonCount = 2 THEN 
                            PWM Green,127,100
                            ENDIF
                    If ButtonCount = 3 THEN 
                            PWM Blue,127,100
                            ENDIF
                    If ButtonCount = 4 THEN 
                            ButtonCount = 1
                        else
                            ButtonCount = ButtonCount + 1
                        endif
                    endif
            GOTO MAIN
    sorry
    Last edited by mister_e; - 14th August 2011 at 02:12.
    Steve

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

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