Go to Post Also, I'm tired of the "FIRST is a simulation of the real world"-- it isn't. If the real world was like FIRST, there wouldn't be any need for this organization. - cadandcookies [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
 
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 01-02-2007, 20:55
team877's Avatar
team877 team877 is offline
Registered User
FRC #0877 (Cub Robotics)
Team Role: Programmer
 
Join Date: Jan 2007
Rookie Year: 2001
Location: North Dakota
Posts: 52
team877 is an unknown quantity at this point
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   Spotlight this post!  
Unread 01-02-2007, 21:04
Nathan's Avatar
Nathan Nathan is offline
Registered User
FRC #1501 (Team T.H.R.U.S.T.)
Team Role: Alumni
 
Join Date: Sep 2006
Rookie Year: 2007
Location: United States
Posts: 149
Nathan has a spectacular aura aboutNathan has a spectacular aura aboutNathan has a spectacular aura about
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
  #3   Spotlight this post!  
Unread 01-02-2007, 22:44
tdlrali tdlrali is offline
Registered User
FRC #0469 (Las Guerrillas)
Team Role: Programmer
 
Join Date: Sep 2006
Rookie Year: 2006
Location: MI
Posts: 377
tdlrali has much to be proud oftdlrali has much to be proud oftdlrali has much to be proud oftdlrali has much to be proud oftdlrali has much to be proud oftdlrali has much to be proud oftdlrali has much to be proud oftdlrali has much to be proud of
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
  #4   Spotlight this post!  
Unread 02-02-2007, 13:26
Racer26 Racer26 is offline
Registered User
no team
Team Role: Alumni
 
Join Date: Apr 2003
Rookie Year: 2003
Location: Beaverton, ON
Posts: 2,229
Racer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond reputeRacer26 has a reputation beyond repute
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.
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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


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

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


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