Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   C/C++ (http://www.chiefdelphi.com/forums/forumdisplay.php?f=183)
-   -   Button Sequence Input (http://www.chiefdelphi.com/forums/showthread.php?t=134489)

arichman1257 13-02-2015 10:59

Button Sequence Input
 
Is there a relatively simple way, with WPILib or without, to make the code be able to detect an input of a sequence of buttons as oppose to holding them all down? Like a cheat code.

For example, if the driver entered the sequence A B X Y on an xbox controller some LEDs would flash. This mean that they are only pressing one at a time but in sequence.

cgmv123 13-02-2015 11:05

Re: Button Sequence Input
 
Code:

int state = 0;

while{
if buttonA && state == 0
state ++;

if buttonB && state == 1
state ++;

if buttonX && state == 2
state++;

if buttonY && state == 3
state ++;

if buttonBack
state = 0;

if state == 4
{action
state = 0;
}

This is Java-focused pseudocode, but it should be enough to get you started.

Ether 13-02-2015 11:51

Re: Button Sequence Input
 
Quote:

Originally Posted by cgmv123 (Post 1443247)
Code:

int state = 0;

while{
if buttonA && state == 0
state ++;

if buttonB && state == 1
state ++;

if buttonX && state == 2
state++;

if buttonY && state == 3
state ++;

if buttonBack
state = 0;

if state == 4
{action
state = 0;
}

This is Java-focused pseudocode, but it should be enough to get you started.

Shouldn't the state be reset to 0 if a button not in the A B X Y sequence is pressed?

As the code stands, the sequence A B Z X Y would be accepted.




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

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