Go to Post The only thing a team needs to survive is people who want it to survive. - Ryan Foley [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 16-02-2008, 07:59
programmr's Avatar
programmr programmr is offline
Registered User
AKA: Face
FRC #0522
Team Role: Programmer
 
Join Date: Jan 2008
Rookie Year: 2006
Location: Staten Island, NY
Posts: 83
programmr is a jewel in the roughprogrammr is a jewel in the roughprogrammr is a jewel in the rough
Send a message via AIM to programmr
Exclamation Toggle Motor On & Off Help.....

Hello, does anyone know how to program in MPLab this thing... We want pwm02 to turn on if p3_sw_trig was hit. Then, if it's hit again, to shut pwm02 off. Basically like an on or off button. Any help would be greatly appreciated. Thank You.
  #2   Spotlight this post!  
Unread 16-02-2008, 11:15
psy_wombats's Avatar
psy_wombats psy_wombats is offline
Registered User
AKA: A. King
FRC #0467 (Duct Tape Bandits)
Team Role: Programmer
 
Join Date: Jan 2007
Rookie Year: 2007
Location: Shrewsbury MA
Posts: 95
psy_wombats has a spectacular aura aboutpsy_wombats has a spectacular aura aboutpsy_wombats has a spectacular aura about
Re: Toggle Motor On & Off Help.....

This involves storing the last state of your button, something like this:

Code:
void Run_Motor_Button (void)
static unsigned char engage_motor = 0; //Should the motor be on?
static unsigned char last_button_state = 0; //This will be the last position of p3_sw_trig
if (p3_sw_trig && !last_button_state){ //The button is pushed but wasn't last time
engage_motor = !engage_motor //Change what should be happening to the motor
}
last_button_state = p3_sw_trig; //Update the state of the button
if (engage_motor){ //Use the motor if needed
pwm02 = 255;
} else {
pwm02 = 127;
}
This is a good thing to know how to do, as it is used fairly often. I advise that instead of copy/pasting the code that you read the comments and write a similar routine yourself.
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
Getting Gear off of Fisher Price Motor Denman625 Motors 2 12-02-2008 20:58
Off Season Software for Rack & Roll Kims Robot Off-Season Events 0 22-10-2007 14:54
2005 Off-Season Competitions; A list of what, when, & where Erin Rapacki Off-Season Events 2 25-01-2005 14:23
Novi Kick-off & Workshop Dung H Cao Thanks and/or Congrats 0 06-01-2002 09:37


All times are GMT -5. The time now is 00:54.

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