/*
Critical Making Prompt - Build a Non-human
Scaffold code
Matt Ratto
This code instantiates a knock-knock joke bot
It
Look here for more details on code functions:
https://www.arduino.cc/reference/en/language/variables/data-types/stringobject/
https://www.arduino.cc/reference/en/language/variables/data-types/array/
https://www.arduino.cc/en/Tutorial/BuiltInExamples/SwitchCase
https://www.arduino.cc/reference/en/language/functions/communication/serial/readstring/
*/
// Data
String intro[3] = {"Hello, I would like to ask you a few questions.", "Can I ask you more questions?", "Sorry, I only know these questions"};
String questions[2] = {"What is your favourite color", "How many hotdogs can you eat?"};
String firstAnswers[2] = {"That is a nice colour", "I love that"};
String secondAnswers[2] = {"Keep going", "Good job"};
int state = 0;
int questionVal = 0;
String firstInput;
String secondInput;
void setup() {
// initialize serial communication:
Serial.begin(9600); //start serial port
delay(1000);
Serial.println("Hello and welcome to the bot");
delay(100);
/*
Serial.println("Data");
for (int i=0; i<2; i++){
Serial.println(questions[i]);
}
for (int i=0; i<2; i++){
Serial.println(firstAnswers[i]);
}
for (int i=0; i<2; i++){
Serial.println(secondAnswers[i]);
}
*/
}
void loop() {
switch (state) { //start state machine
case 0: // get input
firstQuestion();
break;
case 1: // second joke
secondQuestion();
break;
case 2: // second joke
calculation();
break;
} //end state machine
} //end loop
///begin functions
String userInput(){
String input;
bool stillEntering = true;
while (stillEntering){
if (Serial.available()) {
char c = Serial.read();
if (c == '\n') {
stillEntering =false;
}else{
input = input + c;
}
}
}
return input;
}
void firstQuestion(){
Serial.println(questions[state]);
firstInput = userInput();
if (firstInput.indexOf("Pink")>=0){
Serial.println(firstAnswers[1]);
}else{
Serial.println(firstAnswers[0]);
}
state = 1;
}
void secondQuestion(){
Serial.println(questions[state]);
secondInput = userInput();
Serial.println(secondInput.toInt());
if (secondInput.toInt()<=3) {
Serial.println(secondAnswers[1]);
}else{
Serial.println(secondAnswers[0]);
}
state = 2;
}
void calculation(){
if (firstInput.length()+secondInput.toInt() >2){
Serial.println("I am super impressed");
}else{
Serial.println("You could do better");
}
state = 0;
}