![]() |
Mapping Buttons to PWMs
Hey guys, how can i map a joystick button to say put pwm08 = 200
Thanks -Nick a.k.a n00b under stress |
Re: Mapping Buttons to PWMs
In a bit of pseudo code
Code:
if(p1_sw_trig) { |
Re: Mapping Buttons to PWMs
say you want the trigger to set pwm3 to 200 when pressed, 127 when not:
if(p1_sw_trig) pwm03 = 200; else pwm03 = 127; any of the button status variables will work in the if statement. --edit-- lol, apparently ryan and I are both forum hawks ;) |
Re: Mapping Buttons to PWMs
now where do i throw this code?
In default routine? -Nivk |
Re: Mapping Buttons to PWMs
A good majority of the working modifications you make to the default code will go into user_routine.c, but you will want to throw your autonomous code into a specified area of user_routine_fast.c. There actually is a section of the user_routine.c file that is marked with comments indicating that that is where you need to include custom code. Hope that helps.
|
Re: Mapping Buttons to PWMs
Another composition of this if-statement would be:
(p1_sw_trig)?pwm03 = 200:pwm03 = 127; |
Re: Mapping Buttons to PWMs
or even (if you want to be fancy)
pwm03 = p1_sw_trig ? 200 : 127; as a general rule of thumb, if you're working from the default code without massive modifications, anything dealing with user control (such as button mapping) will go in Default_Routine(). |
Re: Mapping Buttons to PWMs
If you want to skip the if statement, you can use the following code
pwm03 = 127 + 63 * p1_sw_trig; If you want your motor to be able to go backwards also, you can use 2 switches with the following code. pwm03 = 127 + (63 * p1_sw_trig) - (63 * p1_sw_top); |
Re: Mapping Buttons to PWMs
Quote:
but yes, for the FRC, one could use Joe's code. |
Re: Mapping Buttons to PWMs
Quote:
Oh, and yall don't know how lucky you have it (well, most of you do). Back in my day, we didn't have your stinkin' order of operations, and had to cram our code full of paretheses. (Or, more accurately, casually forget to do so and hit yourself when you see robot go crazy.) Yet another benefit of C over PBASIC. I, for one, am breathing a sight of relief. |
| All times are GMT -5. The time now is 07:49. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi