No just the code that you asked me to try.
No just the code that you asked me to try.
Now let's make sure that button is working. Modify the main to be this:
That should have all three lit as before unless you press the button, then it should skip the green gosub. Btw, is the tris for the button set to input? Also I am a lazy typer, so I assume you will make the names be what they need to be like button shoud really be switchpin (i think)Code:main: Gosub red If button =1 then goto skipgreen Gosub green Skipgreen: Gosub blue Goto main
Last edited by cncmachineguy; - 14th August 2011 at 03:52.
-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!
Im not sure how to set tris on GPIO.3 I assumed because the datasheet says its an input only pin, i didnt have to futz with it. When i run your code above, i get Red, Green, Back to Red. If i tap the switch, the whole circuit turns off and stays off while i hold it. I never see blue.
Well thats just wierd that it skips blue always. but the the whole circuit turning off makes perfect sense. If you look at the gp3 pin, it is input only because it is shared with MCLR. that is the external reset pin. Since you have no configs listed, I assume you are using the defaults. I went and looked at 10f202.inc in the PBP folder and the default config has MCLR_ON. this means GP3 is set to be the reset when low. so I am sure you are reseting the chip, or at least not looking at it as an input.
2 choices here: Assuming you are NOT using PBP3, you can change the .inc file to MCLR_OFF and leave it as that, or you can comment the configs all together and put them in your code;
If you are using PBP3, you can use the brand new #config block format and set your configs in your code
BTW, I am going to assume the blue not working may have something to do with the MCLR issue for now. Also I guess you are right about the TRIS, but I would get in the habit of just ALWAYS setting it. Life will be easier later for you that way.
Last edit: Please post your current code now so we know where you are.
Last edited by cncmachineguy; - 14th August 2011 at 04:13.
-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!
Code posted below. I dont get whats going on now. When i power the circuit on, it blinks red, pauses, then blinks green, pauses and goes back to red. I am not pressing the switch at all. And i turned off MCLRE in the INC file like you suggested. I see nothing in the code saying to blink. When i press the button, it stops doing everything until i power cycle the circuit.
Code:OPTION_REG.5 = 0 Red var GPIO.0 Green var GPIO.1 Blue var GPIO.2 SwitchPin var GPIO.3 ButtonCount VAR BYTE ButtonCount = 1 HIGH Red HIGH Green HIGH Blue MAIN: IF SwitchPin = 1 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
Hi Brian
Take a look at this code. ButtonCount starts with 0 and then loops between 1 and 3 depending on your button presses. You may want it to roll over to 0 and have an all off program too. EDIT : My post assumes you are using a high input as indication of switch being pressed.
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: SWITCHLOOP: if SwitchPin = 1 then ButtonCount = ButtonCount+1 if ButtonCount > 3 then ButtonCount = 1 while SwitchPin = 1: wend ' wait here while the switch remains pressed endif If ButtonCount = 1 THEN GOSUB RedProgram If ButtonCount = 2 THEN GOSUB GreenProgram If ButtonCount = 3 THEN GOSUB BlueProgram GOTO SWITCHLOOP END RedProgram: PWM Red,127,100 RETURN GreenProgram: PWM Green,127,100 RETURN BlueProgram: PWM Blue,127,100 RETURN END
I wish i could reply back and say that works.. But it doesnt. Its randomly cycling through each color in order (i.e.; Red, Green, Blue, etc.) without me pressing anything. Also, Im thinking i screwed up in the code i provided where the color should always stay lit UNTIL the switch is pressed, so the program always needs to be waiting for a switch press, then it changes color.
Bookmarks