Newbie help. RGB Led on a PIC10F202


Closed Thread
Results 1 to 40 of 42

Hybrid View

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

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

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

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

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

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

    Steve, wonderful examples, I think th OP may have a few questions for you, especially in the last with port indexing. But why doesn't his work after he moved the IF into the switchloop section? BTW, he will still have problems with button press being 1 for a zillion loop iterations, don't ya think?

    @Brian, if you press the switch repeatedly, will that make the other LED's light? If so, does it seem to be random as to which will light?
    -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!

  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

    Quote Originally Posted by cncmachineguy View Post
    Steve, wonderful examples, I think th OP may have a few questions for you, especially in the last with port indexing. But why doesn't his work after he moved the IF into the switchloop section? BTW, he will still have problems with button press being 1 for a zillion loop iterations, don't ya think?

    @Brian, if you press the switch repeatedly, will that make the other LED's light? If so, does it seem to be random as to which will light?
    Many thanks Steve for those examples. I tried both of your last ones just above this post and neither seem to be working. It does not light upon circuit power nor if i press the button to cycle through the other colors.

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