예제 #1
0
int titles(int title) {
	switch(title){
	case 0:
		break;
	case 1:
		string first = "Auto Pick: ";
		string second = "";
		displayLCD(first, second);
		waitForPress();
		if(nLCDButtons == leftButton)
		{
			return redPick;
		} 
		else if(nLCDButtons == rightButton)
		{
			return bluePick;
		}
		else if(nLCDButtons == centerButton)
		{
			return batteryButton;
		}
		break;
	case 2:
		waitForPress();
		if(nLCDButtons == centerButton)
		{
			return autoPick;
		}
		break;
	default:
		return -1;

	}
}
예제 #2
0
int waitForButtonPress() {
	int btnPressed;
	waitForPress();
	btnPressed = nLCDButtons;
	waitForRelease();
	return btnPressed; //return the buttons that were pressed
}
예제 #3
0
void incrementOrDecrement() 
{ 
    waitForPress(); 
    //Increment or decrement "AutonomousNumber" based on button press 
            if(nLCDButtons == leftButton) 
            { 
                waitForRelease(); 
                AutonomousNumber--; 
                if (AutonomousNumber < 0) 
                { 
                    AutonomousNumber = NUMBER_OF_MODES; 
                } 
            } 
            else if(nLCDButtons == rightButton) 
            { 
                waitForRelease(); 
                AutonomousNumber++; 
                if (AutonomousNumber > NUMBER_OF_MODES) 
                { 
                    AutonomousNumber = 0; 
                } 
            } 
} 
예제 #4
0
task LCDSelect() {
	if (showVersion) {
		clearLCD();
		displayLCDCenteredString(0,"LCD Select v2.0-f"); //briefly display version for debug purposes
		wait1Msec(750);
	}
	showVersion = false; //don't show the version again if autonSelection is ever reset


	//Q1: Which side?
	showOnLCD("Which side?","Left  Right  Sk.");
	waitForPress();
	int q1Response = nLCDButtons;
	waitForRelease();
	int q2Page = 1; //1 - Big/Small choices shown, 2 - Cube/Fence choices shown, 3 - Nothing choice shown
	int q2Response = 0;
	int q2PlayChosen = 0;

	if (q1Response != 4) {

		while (q2PlayChosen == 0) {

			if (q2Page == 1) {
				if (LCD_CUBE && LCD_STARS) {
					showOnLCD("Choose play: 1/2","Cube   Star   >>");
				} else if (LCD_CUBE && !LCD_STARS) {
				  showOnLCD("Choose play:","Cube          >>");
				} else if (!LCD_CUBE && LCD_STARS) {
				  showOnLCD("Choose play:","       Star   >>");
				} else {
					showOnLCD("Press any btn","");
				}

				wait1Msec(250); //short delay to prevent button press from triggering multiple times
				waitForPress();
				q2Response = nLCDButtons;
				if (q2Response == 4) {
					q2Page = 3;
				} else if (q2Response == 1) {
					q2PlayChosen = 1;
				} else if (q2Response == 2) {
					q2PlayChosen = 2;
				}
				waitForRelease();
				if (q2Response == 1 ||q2Response == 2) {
					break;
				}

			}/* else if (q2Page == 2) {
				showOnLCD("Choose play: 2/3","Cube   Fence  >>");
				wait1Msec(250);
			  waitForPress();
				q2Response = nLCDButtons;
				if (q2Response == 4) {
					q2Page = 3;
				} else if (q2Response == 1) {
					q2PlayChosen = 3;
				} else if (q2Response == 2) {
					q2PlayChosen = 4;
				}
				waitForRelease();
				if (q2Response == 1 ||q2Response == 2) {
					break;
				}
			} */else if (q2Page == 3) {
				showOnLCD("Choose play: 2/2","Nothing       >>");
				wait1Msec(250);
			  waitForPress();
				q2Response = nLCDButtons;
				if (q2Response == 4) {
					q2Page = 1;
				} else if (q2Response == 1) {
					q2PlayChosen = 4;
				}
				waitForRelease();
				if (q2Response == 1 ||q2Response == 2) {
					break;
				}
			} //end else if
		} //end while
	} //end if


	if (q1Response == 4) {
		AUTON_PLAY = 3;
		playConfirmName = "Prog. skills";
	} else {
		if (q1Response == 1) {
			AUTON_SIDE = LEFT;
		} else { //q1Response == 2
			AUTON_SIDE = RIGHT;
		}
		switch (q2PlayChosen) {
			case 1:
				AUTON_PLAY = 1;
				playConfirmName = "Cube";
				break;
			case 2:
				AUTON_PLAY = 2;
				playConfirmName = "Back stars";
				break;
			//case 3 would be programming skills, which is handled above
			case 4:
				AUTON_PLAY = 4;
				playConfirmName = "NOTHING";
				break;
		}
	}

	startTask(confirmChoice);
	wait1Msec(250);
	int confirmResult = waitForButtonPress();
	stopTask(confirmChoice);
	if (confirmResult == 2) {
		if (AUTON_PLAY == 5) {
			showOnLCD("NOTHING","No auton!");
		} else {
			showOnLCD(playConfirmName,"will run!");
		}
	} else {
		startTask(restartAutonSelection);
	}



} //end task
예제 #5
0
Button ButtonSubscription::waitForPress() {
    return waitForPress(portMAX_DELAY);
}
// wait for any of the specified buttons to be pressed and then released,
// at which point execution will return from this method.  The argument
// 'buttons' can refer to multiple buttons using the bitwise OR operator |.
// The return value is the ID of the button that was pressed and released.
// Note that this method takes care of button debouncing.
// Example: waitForButton(TOP_BUTTON | BOTTOM_BUTTON);
unsigned char OrangutanPushbuttons::waitForButton(unsigned char buttons)
{
  unsigned char pressedButton = waitForPress(buttons);
  waitForRelease(pressedButton);
  return pressedButton;
}
void pre_auton()
{


	//------------- Beginning of User Interface Code ---------------
	//Clear LCD
	clearLCDLine(0);
	clearLCDLine(1);
		bLCDBacklight = true;
	//Loop while center button is not pressed
	while(nLCDButtons != centerButton)
	{
		//Switch case that allows the user to choose from 4 different options
		switch(count){
		case 0:
			//Display first choice
			displayLCDCenteredString(0, "Red Middle");
			displayLCDCenteredString(1, "<		 Enter		>");
			waitForPress();
			//Increment or decrement "count" based on button press
			if(nLCDButtons == leftButton)
			{
				waitForRelease();
				count = 3;
			}
			else if(nLCDButtons == rightButton)
			{
				waitForRelease();
				count++;
			}
			break;
		case 1:
			//Display second choice
			displayLCDCenteredString(0, "blue Middle");
			displayLCDCenteredString(1, "<		 Enter		>");
			waitForPress();
			//Increment or decrement "count" based on button press
			if(nLCDButtons == leftButton)
			{
				waitForRelease();
				count--;
			}
			else if(nLCDButtons == rightButton)
			{
				waitForRelease();
				count++;
			}
			break;
		case 2:
			//Display third choice
			displayLCDCenteredString(0, "RED hang");
			displayLCDCenteredString(1, "<		 Enter		>");
			waitForPress();
			//Increment or decrement "count" based on button press
			if(nLCDButtons == leftButton)
			{
				waitForRelease();
				count--;
			}
			else if(nLCDButtons == rightButton)
			{
				waitForRelease();
				count++;
			}
			break;
		case 3:
			//Display fourth choice
			displayLCDCenteredString(0, "Blue hang");
			displayLCDCenteredString(1, "<		 Enter		>");
			waitForPress();
			//Increment or decrement "count" based on button press
			if(nLCDButtons == leftButton)
			{
				waitForRelease();
				count--;
			}
			else if(nLCDButtons == rightButton)
			{
				waitForRelease();
				count = 0;
			}
			break;
		default:

			count = 0;

			break;

		}
	}

}
void pre_auton(){

	bLCDBacklight = true;	// Turn on LCD Backlight

	clearLCDLine(0);
	clearLCDLine(1);

	//Display the Primary Robot battery voltage
	displayLCDString(0, 0, "Primary: ");
	sprintf(mainBattery, "%1.2f%c", nImmediateBatteryLevel/1000.0, 'V'); //Build the value to be displayed
	displayNextLCDString(mainBattery);

	//Display the Backup battery voltage
	displayLCDString(1, 0, "Backup: ");
	sprintf(backupBattery, "%1.2f%c", BackupBatteryLevel/1000.0, 'V');	//Build the value to be displayed
	displayNextLCDString(backupBattery);

	//Short delay for the LCD refresh rate
	waitForPress();

	// Clear LCD
	clearLCDLine(0);
	clearLCDLine(1);

	wait1Msec(500);

	//Declare count variable to keep track of our choice

	int count = 0;

	while(nLCDButtons != centerButton)
	{
		//Switch case that allows the user to choose from 5 different options
		switch(count){

			case 0: //Display first choice
				displayLCDCenteredString(0, "Goal Auto red");
				displayLCDCenteredString(1, "<     Enter    >");
				waitForPress();

				//Increment or decrement "count" based on button press
				if(nLCDButtons == leftButton)
				{
					waitForRelease();
					count--;
				}

				else if(nLCDButtons == rightButton)
				{
					waitForRelease();
					count++;
				}
				break;
			case 1: //display 2nd choice
				displayLCDCenteredString(0, "Goal Auto Blue");
				displayLCDCenteredString(1, "<     Enter    >");


				if(nLCDButtons == leftButton) {
					waitForRelease();
					count--;
				}
				else if(nLCDButtons == rightButton) {
					waitForRelease();
					count++;
				}
				break;

			default:
				count = 0;
				break;
		}

		switch(count){
			case 2: //Display 3rd choice
				displayLCDCenteredString(0, " Blue Hang auto");
				displayLCDCenteredString(1, "<     Enter    >");
				waitForPress();
				//Increment or decrement "count" based on button press
				if(nLCDButtons == leftButton) {
					waitForRelease();
					count--;
				}

				else if(nLCDButtons == rightButton) {
					waitForRelease();
					count++;
				}
				break;

			case 3: //display 4th choice
				displayLCDCenteredString(0, "Red Hang auto");
				displayLCDCenteredString(1, "<     Enter    >");


				if(nLCDButtons == leftButton) {
					waitForRelease();
					count--;
				}
				else if(nLCDButtons == rightButton) {
					waitForRelease();
					count++;
				}
				break;

				default:
				count = 0;
				break;

							case 4: //display 5th choice
				displayLCDCenteredString(0, "Skills Challenge");
				displayLCDCenteredString(1, "<     Enter    >");


				if(nLCDButtons == leftButton) {
					waitForRelease();
					count--;
				}
				else if(nLCDButtons == rightButton) {
					waitForRelease();
					count++;
				}
				break;

				default:
				count = 0;
				break;
		}
		//Clear LCD
		clearLCDLine(0);
		clearLCDLine(1);

		switch(count) {  //pick auto, display
			case 0: //Choice 1 from LCD
				displayLCDCenteredString(0, "Red Goal Auto");
				displayLCDCenteredString(1, "is running!");
				wait1Msec(1000);
				programChoice = 1;
				break;

			case 1: //Choice 2 from LCD
				displayLCDCenteredString(0, "Blue Goal Auto");
				displayLCDCenteredString(1, "is running!");
				wait1Msec(1000);
				programChoice = 2;
				break;

			case 2: //Choice 2 from LCD
				displayLCDCenteredString(0, "Blue Hang Auto");
				displayLCDCenteredString(1, "is running!");
				wait1Msec(1000);
				programChoice = 3;
				break;

			case 3: //Choice 3 from LCD
				displayLCDCenteredString(0, "Red Hang Auto");
				displayLCDCenteredString(1, "is running!");
				wait1Msec(1000);
				programChoice = 4;
				break;

			case 4: //Choice 3 from LCD
				displayLCDCenteredString(0, "Skills Challenge");
				displayLCDCenteredString(1, "is running!");
				wait1Msec(1000);
				programChoice = 5;
				break;

			default:
				displayLCDCenteredString(0, "No valid choice");
				displayLCDCenteredString(1, "was made!");
				wait1Msec(1000);
				break;
		}
	}
}
예제 #9
0
void lcdPreAuton()
{
	//Clear LCD
	clearLCDLine(0);
	clearLCDLine(1);
	//Loop while center button is not pressed
	while(lcdTerminate == false)
	{
		while(nLCDButtons != centerButton)
		{
			switch(colorCount)
			{
				case 0:
					//Display first choice
					displayLCDCenteredString(0, "Red");
					displayLCDCenteredString(1, "<		 Enter		>");
					waitForPress();
					//Increment or decrement "count" based on button press
					if(nLCDButtons == leftButton)
					{
						waitForRelease();
						colorCount = 1;
					}
					else if(nLCDButtons == rightButton)
					{
						waitForRelease();
						colorCount = 1;
					}
					ifRed = true;
					ifBlue = false;
					break;
				case 1:
					//Display first choice
					displayLCDCenteredString(0, "Blue");
					displayLCDCenteredString(1, "<		 Enter		>");
					waitForPress();
					//Increment or decrement "count" based on button press
					if(nLCDButtons == leftButton)
					{
						waitForRelease();
						colorCount = 0;
					}
					else if(nLCDButtons == rightButton)
					{
						waitForRelease();
						colorCount = 0;
					}
					ifBlue = true;
					ifRed = false;
					break;
			}
		}
		wait10Msec(10);
		//next go to side selection
		waitForRelease();
		if(ifBlue == true && ifRed == false)
		{
			while(nLCDButtons != centerButton)
			{
				switch(sideCount)
				{
					case 0:
						displayLCDCenteredString(0, "Left");
						displayLCDCenteredString(1, "<		 Enter		>");
						waitForPress();
						if(nLCDButtons == leftButton)
						{
							waitForRelease();
							sideCount = 1;
						}
						else if(nLCDButtons == rightButton)
						{
							waitForRelease();
							sideCount = 1;
						}
						autonCount = 0;
						break;
					case 1:
						displayLCDCenteredString(0, "Right");
						displayLCDCenteredString(1, "<		 Enter		>");
						waitForPress();
						if(nLCDButtons == leftButton)
						{
							waitForRelease();
							sideCount = 0;
						}
						else if(nLCDButtons == rightButton)
						{
							waitForRelease();
							sideCount = 0;
						}
						autonCount = 1;
						break;
				}
			}
		}
		else if(ifBlue == false && ifRed == true)
		{
			while(nLCDButtons != centerButton)
			{
				switch(sideCount)
				{
					case 0:
						displayLCDCenteredString(0, "Left");
						displayLCDCenteredString(1, "<		 Enter		>");
						waitForPress();
						if(nLCDButtons == leftButton)
						{
							waitForRelease();
							sideCount = 1;
						}
						else if(nLCDButtons == rightButton)
						{
							waitForRelease();
							sideCount = 1;
						}
						autonCount = 2;
						break;
					case 1:
						displayLCDCenteredString(0, "Right");
						displayLCDCenteredString(1, "<		 Enter		>");
						waitForPress();
						if(nLCDButtons == leftButton)
						{
							waitForRelease();
							sideCount = 0;
						}
						else if(nLCDButtons == rightButton)
						{
							waitForRelease();
							sideCount = 0;
						}
						autonCount = 3;
						break;
				}
			}
		}
		wait10Msec(10);
		waitForRelease();
		while(nLCDButtons !=centerButton)
		{
		switch(delayCount){
		case 0:
			//Display first choice
			displayLCDCenteredString(0, "Delay");
			displayLCDCenteredString(1, "< 0 seconds >");
			waitForPress();
			//Increment or decrement "count" based on button press
			if(nLCDButtons == leftButton)
			{
				waitForRelease();
				delayCount = 3;
			}
			else if(nLCDButtons == rightButton)
			{
				waitForRelease();
				delayCount++;
			}
			delayer1 = 0;
			break;
		case 1:
			//Display second choice
			displayLCDCenteredString(0, "Delay");
			displayLCDCenteredString(1, "< 3 seconds >");
			waitForPress();
			//Increment or decrement "count" based on button press
			if(nLCDButtons == leftButton)
			{
				waitForRelease();
				delayCount--;
			}
			else if(nLCDButtons == rightButton)
			{
				waitForRelease();
				delayCount++;
			}
			delayer1 = 3;
			break;
		case 2:
			//Display third choice
			displayLCDCenteredString(0, "Delay");
			displayLCDCenteredString(1, "< 5 seconds >");
			waitForPress();
			//Increment or decrement "count" based on button press
			if(nLCDButtons == leftButton)
			{
				waitForRelease();
				delayCount--;
			}
			else if(nLCDButtons == rightButton)
			{
				waitForRelease();
				delayCount++;
			}
			delayer1 = 5;
			break;
		case 3:
			//Display fourth choice
			displayLCDCenteredString(0, "Delay");
			displayLCDCenteredString(1, "< 7 seconds >");
			waitForPress();
			//Increment or decrement "count" based on button press
			if(nLCDButtons == leftButton)
			{
				waitForRelease();
				delayCount--;
			}
			else if(nLCDButtons == rightButton)
			{
				waitForRelease();
				delayCount = 0;
			}
			delayer1 = 7;
			break;
		default:
			delayCount = 0;
			break;
		}
		lcdTerminate = true;
	}
}
}