Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   making a trigger a toggle (http://www.chiefdelphi.com/forums/showthread.php?t=53247)

team877 01-02-2007 20:55

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?

Nathan 01-02-2007 21:04

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."
}

I hope that helps :)
-Nathan

tdlrali 01-02-2007 22:44

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;

with any toggle code, if your output switches state rapidly a few times after your input is pressed, you might need to add a little delay to debounce the input

Racer26 02-02-2007 13:26

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;

That should toggle relay1's fwd direction each time there is a 0->1 transition on the port 1 trigger.


All times are GMT -5. The time now is 03:59.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi