Example #1
0
// Polls the inputs and obtains new sensor readings. 
// Updates LED indicators and detects button presses
void Update()
{
	// Gets new sensor readings
	left = analogRead(LEFT_SENSOR);
	right = analogRead(RIGHT_SENSOR);
	leftDetected = left < thresholdLeft;
	rightDetected = right < thresholdRight;

	// Detects button presses and decrements the LCD counter
	if(StopButton()) MENU = true;
	if(StartButton()) MENU = false;
	lcdRefreshCount = (lcdRefreshCount <= 0) ? lcdRefreshPeriod : (lcdRefreshCount - 1);

	// Reverse direction if bumper pressed
	if(LeftBumper()) direction = RIGHT;
	else if (RightBumper()) direction = LEFT;
}
Example #2
0
// Polls the inputs and obtains new sensor readings. 
// Updates LED indicators and detects button presses
void Update()
{
	// Gets new sensor readings
	left = analogRead(LEFT_SENSOR);
	right = analogRead(RIGHT_SENSOR);
	leftDetected = left > threshold;
	rightDetected = right > threshold;

	// Updates the LED tape-detect indicators. Pin logic is inverted
	digitalWrite(LEFT_LED, !leftDetected);
	digitalWrite(RIGHT_LED, !rightDetected);
	digitalWrite(ERROR_LED, !((!leftDetected) && (!rightDetected)));

	// Detects button presses and decrements the LCD counter
	if(StopButton()) MENU = true;
	if(StartButton()) MENU = false;
	lcdRefreshCount = (lcdRefreshCount <= 0) ? lcdRefreshPeriod : (lcdRefreshCount - 1);

	// Reverse direction if bumper pressed
	if(LeftBumper()) direction = RIGHT;
	else if (RightBumper()) direction = LEFT;
}