Quizbot Code: Ask a Question

Step 1:
-
Follow the Configuration instructions to connect your Quizbot to RobotMoose.com.
Connect to your robot at the Robots page.
Open the Code tab and click "New" to create a new experiment. In our example, we call it "Question."
The label() function displays text on the User Interface (UI) tab. Enter your question into the parentheses of the label() function, as in our example below, and click "Run" to display it.

Step 2:
The button() function adds a button to the UI tab.Add a button for each answer to the question, as many as you want, and click "Run." You will be able to click the buttons, but they won't do anything yet.

Step 3:
Use the Add State button to create two new states. Call one "yes" and the other "no".
Step 4:
In the "yes" state, add three lines of code:- A label to display the message "Correct!"
- A delay of 1000 milliseconds (1 second).
- The line state = "start" to return to the start state

Step 5:
Now we need to make each button connect to one of the "yes" or "no" states.To connect a button to a state, add the name of the state after the name of the button, separated by a comma, like this: button("Purple", "no")
Connect each correct answer to the "yes" state, and each incorrect answer to the "no" state, as in the example below, and click "Run".
Now each time you click one of the buttons, it will display either "Correct" or "Incorrect" for one second and then return to the question.

Step 6:
All that is left is to add code to make the Quizbot respond to the answers.To begin, experiment with the Drive tab to find which Quizbot servo is servo[0] and which is servo[1]. In our example, the up-down servo is servo[1]. Then add these lines of code:
- Anywhere in the "start" state, add code to set the servos to their starting position. We used 90 degrees for the left-right servo and 160 degrees for the up-down servo.
- At the top of the "yes" state, set the up-down servo to another angle to make it nod. We used 90 degrees.
- At the top of the "no" state, set the left-right servo to another angle to make it shake its head no. We used 120 degrees.

Congratulations, your code is complete! Run the code and try out your question. Ask other students to answer the question as well!