Tags
electronicsarduino
Date
Author
U
UntitledDocumentation Type
Class
Beyond Possible
Class Section
Careers of the future
‣
What is a state machine?
Getting Started
We’re going to modify some code to create a simple state machine to control our robot. This state machine will have two states, “SEARCH” and “FOLLOW”. Right now, only “FOLLOW” is working in the code.

Step 1: Download the state machine template and open in Arduino IDE
Step 2: Add a new “SEARCH” state
Under line 41, add an else {}
statement to make “SEARCH” our default state.
else {
state = "SEARCH";
}
Step 3: Add the behavior for the “SEARCH” state
Under line 72, add an else if {}
statement to hold the “SEARCH” behavior.
else if(state == "SEARCH") {
turnLeft();
}
Step 4: Test your code
What does your robot do when it doesn’t identify any objects?