|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
making a trigger a toggle
how can i set my relay on my controller to just turn a pwm port to on or off so that i dont have to hold down the trigger?
|
|
#2
|
||||
|
||||
|
Re: making a trigger a toggle
Hi, I'll post below what I'm using right now... As a sidenote, I have two variables you'll need. One is name "port1_trigger" and the other "Lift."
Code:
void Lift_Control ( void )
{
if ( port1_trigger == 1 ) // If the trigger was pressed last.
{
Last_Button_Pressed = 1 ; // Then the trigger was pressed last.
}
if ( port1_thumb == 1 )
{ // If the thumb button was pressed last.
Last_Button_Pressed = 2 ; // Then the thumb button was pressed last.
}
if ( Last_Button_Pressed == 1 ) // If the last button pressed was the trigger, then....
{
Lift = 1 ; // Lift the platform!
}
else
{
Lift = 0 ; // Don't lift the platform.
}
SetRelay ( 1 , Lift , -1 ) ; // The spike relay will have the value of the variable "Lift."
}
![]() -Nathan |
|
#3
|
|||
|
|||
|
Re: making a trigger a toggle
Code:
static char p1_trig_state = 1;
static unsigned char p1_trig_pressed = 0;
if(p1_sw_trig && !p1_trig_pressed) {
p1_trig_state *= -1;
p1_trig_pressed = 1;
}
else if(!p1_sw_trig)
p1_trig_pressed = 0;
if(p1_trig_state==1)
pwm01 = 255;
else
pwm01 = 127;
|
|
#4
|
|||
|
|||
|
Re: making a trigger a toggle
well, if you're trying to turn a motor/solenoid/whatever else on/off only, without variable speed, i would use a spike. the code is simple.
Code:
static char trigold = 0; // Define this with global scope
if(p1_sw_trig == 1 && trigold == 0){
relay1_fwd = !relay1_fwd;
}
trigold = p1_sw_trig;
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| 360 Button, trigger, and joy stick? | GMAdan | Programming | 4 | 16-01-2007 19:07 |
| toggle switch | Windward | Programming | 31 | 27-01-2006 22:38 |
| Pneumatics on a toggle switch | Idaman323 | Programming | 3 | 15-02-2005 18:42 |
| Ball Chute Trigger | pludodog | Technical Discussion | 1 | 12-01-2004 10:26 |
| Toggle? | f22flyboy | Programming | 5 | 03-11-2002 08:03 |