The code below doesn’t have most of the questions in the game, but has the full shell.
This shows how to MOVI can be setup with question and answers and feed out responses to groups of questions in order. This can feel like you passed a level like when playing a video game. Have fun.
If you try it out, you might want to print or look at the source code to know what to say. This will let you know what to say. You must ask the first first questions first. Then the next eight must be answered. Then the next sixteen questions…
/*
*The Question Tracking Example started with the code from LightSwitch.ino
*The example showed how to have responses to statements or questions.
*We built on that to have dialog back and forth with the MOVI.
*Questions are only released in groups. Each question asked or each
*correct ansnwer given is tracked using bits. User is given hints if
*they ask a question that is not yet answerable. We tested to 44 questions/responses
*but can be greatly expanded. Fits in Arduino Uno. (EEPROM written to
*only the first time each question is asked. Should last forever…)
*Not really tight or good code, but works.
*by Bob Gross Aaron Gross 4/6/2020
*
- This basic example shows how to use MOVI™’s API to train the call
- sign “Arduino” and two sentences. When the sentences are recognized
- they switch on and off an LED on PIN D13. Many boards have a hardwired
- LED on board already connected to D13.
-
- Circuitry:
- LED is pin D13 and GND
- Arduino UNO R3, MEGA2560 R3, or Arduino Leonardo R3.
- Connect speaker to MOVI.
- IMPORTANT: Always use external power supply with MOVI.
-
- Other Arduino-compatible boards:
- Consult MOVI’s User Manual before connecting MOVI.
-
- If you long-press the button on the MOVI (for a couple seconds),
- MOVI will revert back to the call sign and sentences trained here.
*/
#include <Wire.h>
#include <EEPROM.h>
#include “MOVIShield.h” // Include MOVI library, needs to be before the next #include
#if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_PIC32)
#include <SoftwareSerial.h> // This is nice and flexible but only supported on AVR and PIC32 architecture, other boards need to use Serial1
#endif
//Global Variables for tracking questions answered
// bit31 bit0
// byte3 byte2 byte1 byte0
// 10001000100010001000100010001000
unsigned long QuestionTracker;
unsigned long QuestionTrackerB;
const int led = 13;
MOVI recognizer(true); // Get a MOVI object, true enables serial monitor interface, rx and tx can be passed as parameters for alternate communication pins on AVR architecture
void setup()
{
/*Global Variables for tracking questions answered.
Repeaded here for clarity. If resetting questions
answered on bootup as some questions could be set as
answered by clearing a bit.)
// bit31 bit0
// byte3 byte2 byte1 byte0
// 10001000100010001000100010001000 */
/To reset Questions Answered On Bootup, run the code below.
Otherwise comment it out. Do not comment out, to keep track of questions answered, over power downs./
//QuestionTracker = (0b11111111111111111111111111111110);
//QuestionTrackerB= (0b11111111111111111111111111111111);
//EEPROM.put(0, QuestionTracker);
//EEPROM.put(4, QuestionTrackerB);
//The code belwo loads the saved answers to questions
EEPROM.get(0, QuestionTracker);
bitClear(QuestionTracker, 0); //When starting for the first time on a fresh processor, this is the only bit that needs clearing
EEPROM.put(0, QuestionTracker); //This will clear the first bit, only if needed
EEPROM.get(4, QuestionTrackerB);
pinMode(13, OUTPUT);
recognizer.init(); // Initialize MOVI (waits for it to boot)
recognizer.setSynthesizer(SYNTH_ESPEAK,"-v+m2");
//*
recognizer.callSign(“123”); // Say “one Two Three”, Train call sign was Arduino (may take 20 seconds)
//QuestionTracker
recognizer.addSentence(F(“Who are you?”)); // Add sentence 1
recognizer.addSentence(F(“why are you here?”)); // Add sentence 2
recognizer.addSentence(F(“what is your mission?”)); // Add sentence 3
recognizer.addSentence(F(“Who are the Mice Race?”)); // Add sentence 4
recognizer.addSentence(F(“Why have they come?”)); // Add sentence 5
recognizer.addSentence(F(“Can I help you?”)); // Add sentence 6
recognizer.addSentence(F(“What is the plan?”)); // Add sentence 7
recognizer.addSentence(F(“what is the first step”)); // Add sentence 8
recognizer.addSentence(F(“Tell me more about the Mice Race.”)); // Add sentence 9
recognizer.addSentence(F(“Tell me more about Pete.”)); // Add sentence 10
recognizer.addSentence(F(“What are the Mice Race’s Weaknesses?”)); // Add sentence 11
recognizer.addSentence(F(“What do the Mice Race breath?”)); // Add sentence 12
recognizer.addSentence(F(“Where did the Mice Race come from?”)); // Add sentence 13
recognizer.addSentence(F(“How do you fight them?”)); // Add sentence 14
recognizer.addSentence(F(“Where are the Mice Race now?”)); // Add sentence 15
recognizer.addSentence(F(“Can you see the Mice Race?”)); // Add sentence 16
recognizer.addSentence(F(“This is 17”)); // Add sentence 1
recognizer.addSentence(F(“This is 18?”)); // Add sentence 2
recognizer.addSentence(F(“This is 19”)); // Add sentence 3
recognizer.addSentence(F(“This is 20”)); // Add sentence 4
recognizer.addSentence(F(“This is 21”)); // Add sentence 5
recognizer.addSentence(F(“This is 22”)); // Add sentence 6
recognizer.addSentence(F(“This is 23”)); // Add sentence 7
recognizer.addSentence(F(“This is 24”)); // Add sentence 8
recognizer.addSentence(F(“This is 25”)); // Add sentence 9
recognizer.addSentence(F(“This is 26”)); // Add sentence 10
recognizer.addSentence(F(“This is 27”)); // Add sentence 11
recognizer.addSentence(F(“This is 28”)); // Add sentence 12
recognizer.addSentence(F(“This is 29”)); // Add sentence 13
recognizer.addSentence(F(“This is 30”)); // Add sentence 14
recognizer.addSentence(F(“This is 31”)); // Add sentence 15
//QuestionTrackerB
recognizer.addSentence(F(“This is 32”)); // Add sentence 16
recognizer.addSentence(F(“This is 33”)); // Add sentence 16
//
recognizer.addSentence(F(“This is 34”)); // Add sentence
recognizer.addSentence(F(“This is 35”)); // Add sentence
recognizer.addSentence(F(“This is 36”)); // Add sentence
recognizer.addSentence(F(“This is 37”)); // Add sentence
recognizer.addSentence(F(“This is 38”)); // Add sentence
recognizer.addSentence(F(“This is 39”)); // Add sentence
recognizer.addSentence(F(“This is 40”)); // Add sentence
recognizer.addSentence(F(“This is 41”)); // Add sentence
recognizer.addSentence(F(“This is 42”)); // Add sentence
recognizer.addSentence(F(“This is 43”)); // Add sentence
recognizer.addSentence(F(“This is 44”)); // Add sentence
//Add up to 64 sentances before addtional question tracker variable needed
recognizer.train(); // Train (may take 20seconds)
//*/
Serial.begin(9600);
Serial.println((“Hello”));
//
recognizer.setThreshold(10); // uncomment and set to a higher value (valid range 2-95) if you have a problems due to a noisy environment
}
void loop() // run over and over
{
signed int res=recognizer.poll(); // Get result from MOVI, 0 denotes nothing happened, negative values denote events (see docs)
/* if (res==0)
{ // Sentence
recognizer.say(“I did not understand what you said.”); // Speak a sentence
} */
if (res) //Print the current sentence number
{
Serial.println(res);
}
if (res){ //Send activeity of sentence
digitalWrite(13, HIGH); // sends sentence info to other Arduino
delay(1);
digitalWrite(13, LOW);
}
if (res==1)
{ // Sentence
recognizer.say(F(“I am Palll_toy defender of earth”)); // Speak a sentence
bitClear(QuestionTracker, res);
EEPROM.put(0, QuestionTracker);
//Serial.print("QT = ");
//Serial.println(QuestionTracker);
// Serial.println((“I am Paltoy defender of earth”));
}
if (res==2)
{ // Sentence
recognizer.say(F(“I am here to complete my mission”)); // Speak a sentence
bitClear(QuestionTracker, res);
EEPROM.put(0, QuestionTracker);
//Serial.print("QT = ");
//Serial.println(QuestionTracker);
}
if (res==3)
{ // Sentence
recognizer.say(F(“I’m here to save earth from the Mice Race”)); // Speak a sentence
bitClear(QuestionTracker, res);
EEPROM.put(0, QuestionTracker);
//Serial.print("QT = ");
//Serial.println(QuestionTracker);
}
if (res==4)
{ // Sentence
recognizer.say(F(“the Mice Race are an alien race”)); // Speak a sentence
bitClear(QuestionTracker, res);
EEPROM.put(0, QuestionTracker);
//Serial.print("QT = ");
//Serial.println(QuestionTracker);
}
if (res==5)
{ // Sentence
recognizer.say(F(“The Mice Race came to invade earth”)); // Speak a sentence
bitClear(QuestionTracker, res);
EEPROM.put(0, QuestionTracker);
//Serial.print("QT = ");
//Serial.println(QuestionTracker);
}
if (res==6)
{ // Sentence
recognizer.say(F(“Yes that is why I am here”)); // Speak a sentence
bitClear(QuestionTracker, res);
EEPROM.put(0, QuestionTracker);
//Serial.print("QT = ");
//Serial.println(QuestionTracker);
}
if (res==7)
{ // Sentence
recognizer.say(F(“I don’t know, my mission notes are hidden in my internal memoryy”)); // Speak a sentence
bitClear(QuestionTracker, res);
EEPROM.put(0, QuestionTracker);
//Serial.print("QT = ");
//Serial.println(QuestionTracker);
}
if (res==8) { // Sentence
recognizer.say(F(“ask me questions to search my memoryy”)); // Speak a sentence
bitClear(QuestionTracker, res);
EEPROM.put(0, QuestionTracker);
//Serial.print("QT = ");
//Serial.println(QuestionTracker);
}
if (!(QuestionTracker & 511)) //Only allow responses in this area if first 8 questions are answered. See the “else” below.
{
if (res==9)
{ // Sentence
recognizer.say(F(“The Mice Race are a extraterestrials. They feed off the earth.”)); // Speak a sentence
bitClear(QuestionTracker, res);
EEPROM.put(0, QuestionTracker);
//Serial.print("QT = ");
//Serial.println(QuestionTracker);
// Serial.println((“I am Paltoy defender of earth”));
}
if (res==10)
{ // Sentence
recognizer.say(F(“Pete is who sent me here. He protects humans.”)); // Speak a sentence
bitClear(QuestionTracker, res);
EEPROM.put(0, QuestionTracker);
//Serial.print("QT = ");
//Serial.println(QuestionTracker);
}
if (res==11)
{ // Sentence
recognizer.say(F(“The Mice Race’s only weaknesses is mouse traps.”)); // Speak a sentence
bitClear(QuestionTracker, res);
EEPROM.put(0, QuestionTracker);
//Serial.print("QT = ");
//Serial.println(QuestionTracker);
}
if (res==12)
{ // Sentence
recognizer.say(F(“The Mice Race breath emmisions”)); // Speak a sentence
bitClear(QuestionTracker, res);
EEPROM.put(0, QuestionTracker);
//Serial.print("QT = ");
//Serial.println(QuestionTracker);
}
if (res==13)
{ // Sentence
recognizer.say(F(“The Mice Race come from a far away galaxy.”)); // Speak a sentence
bitClear(QuestionTracker, res);
EEPROM.put(0, QuestionTracker);
//Serial.print("QT = ");
//Serial.println(QuestionTracker);
}
if (res==14)
{ // Sentence
recognizer.say(F(“I need you to cut the cheese to destroy the Mice Race.”)); // Speak a sentence
bitClear(QuestionTracker, res);
EEPROM.put(0, QuestionTracker);
//Serial.print("QT = ");
//Serial.println(QuestionTracker);
}
if (res==15)
{ // Sentence
recognizer.say(F(“I don’t know, We must search to find them.”)); // Speak a sentence
bitClear(QuestionTracker, res);
EEPROM.put(0, QuestionTracker);
//Serial.print("QT = ");
//Serial.println(QuestionTracker);
}
if (res==16) { // Sentence
recognizer.say(F(“Only you can see the Mice Race.”)); // Speak a sentence
bitClear(QuestionTracker, res);
//Serial.print("QT = ");
//Serial.println(QuestionTracker);
}
}
//If the first 8 questions are not yet answered then tell them by hinting
if ((((res)>8)&&(res<17))&&(QuestionTracker&511)) //The ((res) is greater than 8) AND ((res) less than 17) AND (Questions 1-8 are not yet answered)
{
recognizer.say(F(“I dont have access to that data right now.”)); // Speak a sentence
}
if (!(QuestionTracker & 65535)) //Only allow responses in this area if first 16 questions are answered. See the “else” below.
{
if (res==17)
{ // Sentence
recognizer.say(F(“this is 17”)); // Speak a sentence
bitClear(QuestionTracker, res);
EEPROM.put(0, QuestionTracker);
//Serial.print("QT = ");
//Serial.println(QuestionTracker);
}
if (res==18)
{ // Sentence
recognizer.say(F(“this is 18”)); // Speak a sentence
bitClear(QuestionTracker, res);
EEPROM.put(0, QuestionTracker);
//Serial.print("QT = ");
//Serial.println(QuestionTracker);
}
if (res==19)
{ // Sentence
recognizer.say(F(“this is 19”)); // Speak a sentence
bitClear(QuestionTracker, res);
EEPROM.put(0, QuestionTracker);
//Serial.print("QT = ");
//Serial.println(QuestionTracker);
}
if (res==20)
{ // Sentence
recognizer.say(F(“this is 20”)); // Speak a sentence
bitClear(QuestionTracker, res);
EEPROM.put(0, QuestionTracker);
//Serial.print("QT = ");
//Serial.println(QuestionTracker);
}
if (res==21)
{ // Sentence
recognizer.say(F(“this is 21”)); // Speak a sentence
bitClear(QuestionTracker, res);
EEPROM.put(0, QuestionTracker);
//Serial.print("QT = ");
//Serial.println(QuestionTracker);
}
if (res==22)
{ // Sentence
recognizer.say(F(“this is 22”)); // Speak a sentence
bitClear(QuestionTracker, res);
EEPROM.put(0, QuestionTracker);
//Serial.print("QT = ");
//Serial.println(QuestionTracker);
}
if (res==23)
{ // Sentence
recognizer.say(F(“this is 23”)); // Speak a sentence
bitClear(QuestionTracker, res);
EEPROM.put(0, QuestionTracker);
//Serial.print("QT = ");
//Serial.println(QuestionTracker);
}
if (res==24) { // Sentence
recognizer.say(F(“this is 24”)); // Speak a sentence
bitClear(QuestionTracker, res);
EEPROM.put(0, QuestionTracker);
//Serial.print("QT = ");
//Serial.println(QuestionTracker);
}
if (res==25)
{ // Sentence
recognizer.say(F(“this is 25”)); // Speak a sentence
bitClear(QuestionTracker, res);
EEPROM.put(0, QuestionTracker);
//Serial.print("QT = ");
//Serial.println(QuestionTracker);
// Serial.println((“I am Paltoy defender of earth”));
}
if (res==26)
{ // Sentence
recognizer.say(F(“this is 26”)); // Speak a sentence
bitClear(QuestionTracker, res);
EEPROM.put(0, QuestionTracker);
//Serial.print("QT = ");
//Serial.println(QuestionTracker);
}
if (res==27)
{ // Sentence
recognizer.say(F(“this is 27”)); // Speak a sentence
bitClear(QuestionTracker, res);
EEPROM.put(0, QuestionTracker);
//Serial.print("QT = ");
//Serial.println(QuestionTracker);
}
if (res==28)
{ // Sentence
recognizer.say(F(“this is 28”)); // Speak a sentence
bitClear(QuestionTracker, res);
EEPROM.put(0, QuestionTracker);
//Serial.print("QT = ");
//Serial.println(QuestionTracker);
}
if (res==29)
{ // Sentence
recognizer.say(F(“this is 29”)); // Speak a sentence
bitClear(QuestionTracker, res);
EEPROM.put(0, QuestionTracker);
//Serial.print("QT = ");
//Serial.println(QuestionTracker);
}
if (res==30)
{ // Sentence
recognizer.say(F(“this is 30”)); // Speak a sentence
bitClear(QuestionTracker, res);
EEPROM.put(0, QuestionTracker);
//Serial.print("QT = ");
//Serial.println(QuestionTracker);
}
if (res==31)
{ // Sentence
recognizer.say(F(“this is 31”)); // Speak a sentence
bitClear(QuestionTracker, res);
EEPROM.put(0, QuestionTracker);
//Serial.print("QT = ");
//Serial.println(QuestionTracker);
}
}
if ((((res)>16)&&(res<32))&&(QuestionTracker&65535)) //The ((res) is greater than 16) AND
//((res) less than 32) AND
//(Questions 1-15 are not yet answered)
//Give a hint that the question is valid
{
recognizer.say(F(“I dont have access to that data untill later.”)); // Speak a sentence
}
if (!(QuestionTracker)) //We have answered the first 31 questions
{
if (res==32)
{ // Sentence
recognizer.say(F(“this is 32”)); // Speak a sentence
bitClear(QuestionTrackerB, (res-32));
EEPROM.put(4, QuestionTrackerB);
//Serial.print("QT = ");
//Serial.println(QuestionTrackerB);
}
if (res==33)
{ // Sentence
recognizer.say(F(“this is 33”)); // Speak a sentence
bitClear(QuestionTrackerB, (res-32));
EEPROM.put(4, QuestionTrackerB);
//Serial.print("QT = ");
//Serial.println(QuestionTrackerB);
}
if (res==34)
{ // Sentence
recognizer.say(F(“this is 34”)); // Speak a sentence
bitClear(QuestionTrackerB, (res-32));
EEPROM.put(4, QuestionTrackerB);
//Serial.print("QT = ");
//Serial.println(QuestionTrackerB);
}
if (res==35)
{ // Sentence
recognizer.say(F(“this is 35”)); // Speak a sentence
bitClear(QuestionTrackerB, (res-32));
EEPROM.put(4, QuestionTrackerB);
//Serial.print("QT = ");
//Serial.println(QuestionTrackerB);
}
if (res==36)
{ // Sentence
recognizer.say(F(“this is 36”)); // Speak a sentence
bitClear(QuestionTrackerB, (res-32));
EEPROM.put(4, QuestionTrackerB);
//Serial.print("QT = ");
//Serial.println(QuestionTrackerB);
}
if (res==37)
{ // Sentence
recognizer.say(F(“this is 37”)); // Speak a sentence
bitClear(QuestionTrackerB, (res-32));
EEPROM.put(4, QuestionTrackerB);
//Serial.print("QT = ");
//Serial.println(QuestionTrackerB);
}
if (res==38)
{ // Sentence
recognizer.say(F(“this is 38”)); // Speak a sentence
bitClear(QuestionTrackerB, (res-32));
EEPROM.put(4, QuestionTrackerB);
//Serial.print("QT = ");
//Serial.println(QuestionTrackerB);
}
if (res==39)
{ // Sentence
recognizer.say(F(“this is 39”)); // Speak a sentence
bitClear(QuestionTrackerB, (res-32));
EEPROM.put(4, QuestionTrackerB);
//Serial.print("QT = ");
//Serial.println(QuestionTrackerB);
}
if (res==40)
{ // Sentence
recognizer.say(F(“this is 40”)); // Speak a sentence
bitClear(QuestionTrackerB, (res-32));
EEPROM.put(4, QuestionTrackerB);
//Serial.print("QT = ");
//Serial.println(QuestionTrackerB);
}
if (res==41)
{ // Sentence
recognizer.say(F(“this is 41”)); // Speak a sentence
bitClear(QuestionTrackerB, (res-32));
EEPROM.put(4, QuestionTrackerB);
//Serial.print("QT = ");
//Serial.println(QuestionTrackerB);
}
if (res==42)
{ // Sentence
recognizer.say(F(“this is 42”)); // Speak a sentence
bitClear(QuestionTrackerB, (res-32));
EEPROM.put(4, QuestionTrackerB);
//Serial.print("QT = ");
//Serial.println(QuestionTrackerB);
}
if (res==43)
{ // Sentence
recognizer.say(F(“this is 43”)); // Speak a sentence
bitClear(QuestionTrackerB, (res-32));
EEPROM.put(4, QuestionTrackerB);
//Serial.print("QT = ");
//Serial.println(QuestionTrackerB);
}
if (res==44)
{ // Sentence
recognizer.say(F(“this is 44”)); // Speak a sentence
bitClear(QuestionTrackerB, (res-32));
EEPROM.put(4, QuestionTrackerB);
//Serial.print("QT = ");
//Serial.println(QuestionTrackerB);
}
}
if ((((res)>31)&&(res<64))&&(QuestionTracker)) //The ((res) is greater than 31) AND ((res) less than 64) AND (Questions 1-32 are not yet answered)
{
recognizer.say(“I dont have access to that data until more questions are answered.”); // Speak a sentence
}
// Do more …
}