View Single Post
  #5   Spotlight this post!  
Unread 18-12-2013, 00:16
SoftwareBug2.0's Avatar
SoftwareBug2.0 SoftwareBug2.0 is offline
Registered User
AKA: Eric
FRC #1425 (Error Code Xero)
Team Role: Mentor
 
Join Date: Aug 2004
Rookie Year: 2004
Location: Tigard, Oregon
Posts: 486
SoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant future
Re: C++ Toggle Button

Consider this:
Code:
class Posedge_toggle{
	bool value,last;

	public:
	Posedge_toggle():value(0),last(1){}

	void update(bool sample){
		if(sample&&!last) value=!value;
		last=sample;
	}

	bool get()const{ return value; }
};
//...

Posedge_toggle t;
while (IsOperatorControl())
{
    t.update(secondaryController->GetRawButton(6));
    if(t.get()){
        //do tank drive
    }else{
       //do arcade drive
    }
    wait(0.02);
}
It decouples the logic of how to make things toggle from the logic to read joysticks, etc.

Last edited by SoftwareBug2.0 : 18-12-2013 at 00:20. Reason: Inconsistent variable name
Reply With Quote