|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
|||
|
|||
|
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 |
|
#2
|
||||
|
||||
|
Re: Mapping Buttons to PWMs
In a bit of pseudo code
Code:
if(p1_sw_trig) {
// When we hold down the button do this
pwm08 = 200;
}
else {
// When we are not holding down the button, do this
pwm08 = 127;
}
|
|
#3
|
||||
|
||||
|
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 ![]() |
|
#4
|
|||
|
|||
|
Re: Mapping Buttons to PWMs
now where do i throw this code?
In default routine? -Nivk |
|
#5
|
|||||
|
|||||
|
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.
|
|
#6
|
||||
|
||||
|
Re: Mapping Buttons to PWMs
Another composition of this if-statement would be:
(p1_sw_trig)?pwm03 = 200:pwm03 = 127; |
|
#7
|
||||
|
||||
|
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(). |
|
#8
|
||||||
|
||||||
|
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); |
|
#9
|
||||
|
||||
|
Re: Mapping Buttons to PWMs
Quote:
![]() but yes, for the FRC, one could use Joe's code. |
|
#10
|
||||
|
||||
|
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. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Shortcut buttons when posting | Wetzel | CD Forum Support | 2 | 10-12-2003 15:27 |
| Looking for some help with buttons and pins... | Amanda Morrison | General Forum | 4 | 26-02-2003 17:32 |
| Assigning Joystick buttons.... | archiver | 2001 | 5 | 24-06-2002 00:59 |
| Where do the stop buttons go??? | archiver | 2001 | 0 | 24-06-2002 00:35 |
| How many buttons??? | purplehaze357 | Championship Event | 0 | 18-04-2002 23:54 |