Robot Demo App Template
#include <RedBot.h>
/*
Robot Demo
Team Info
Teacher - Class Period
*/
// GLOBAL VARIABLES AND OBJECTS
RedBotButton button;
RedBotMotors motors;
RedBotEncoder encoder(A2, 10);
int LED = 13;
int speaker = 9;
int nextTask = 1;
bool started = false;
// SETUP FUNCTION
void setup() {
// put your setup code here, to run once:
pinMode(LED, OUTPUT);
pinMode(speaker, OUTPUT);
}
// LOOP FUNCTION
void loop() {
// put your main code here, to run repeatedly:
checkButton();
if (started == true) {
// add code to perform when "started"
if (nextTask == 1) task1();
else if (nextTask == 2) task2();
else if (nextTask == 3) task3();
}
else {
// add code to perform when "paused"
motors.stop();
}
}
// CUSTOM FUNCTIONS
void task1() {
// add code to perform task scenario 1
// at end of this task, reset for next task
started = false;
nextTask = 2;
}
void task2() {
// add code to perform task scenario 2
// at end of this task, reset for next task
started = false;
nextTask = 3;
}
void task3() {
// add code to perform task scenario 3
// at end of this task, reset for next task
started = false;
nextTask = 1; // start over
}
void checkButton() {
if (button.read() == true) {
// reverse value of started
started = !started;
// beep and blink as feedback
digitalWrite(LED, HIGH);
tone(speaker, 2000);
delay(200);
digitalWrite(LED, LOW);
noTone(speaker);
delay(200);
}
}