Servo myservo; // create servo object to control a servo // a maximum of eight servo objects can be created
int pos = 180; // variable to store the servo position
void setup() { Serial.begin(9600); delay(10); Serial.println("Welcome to the IEEE 3rd Workshop on Motors"); Serial.println("Answer the questions right to fill up your AWESOME GAUGE");
myservo.attach(9); // attaches the servo on pin 9 to the servo object myservo.write(180); randomSeed(analogRead(0)); }
void loop() { int numOne = random(13); int numTwo = random(13); int guess = 0; int answer = numOne * numTwo; Serial.print("What is "); Serial.print(numOne, DEC); Serial.print(" x "); Serial.print(numTwo, DEC); Serial.println(" ?");
#include
ReplyDeleteServo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created
int pos = 180; // variable to store the servo position
void setup()
{
Serial.begin(9600);
delay(10);
Serial.println("Welcome to the IEEE 3rd Workshop on Motors");
Serial.println("Answer the questions right to fill up your AWESOME GAUGE");
myservo.attach(9); // attaches the servo on pin 9 to the servo object
myservo.write(180);
randomSeed(analogRead(0));
}
void loop()
{
int numOne = random(13);
int numTwo = random(13);
int guess = 0;
int answer = numOne * numTwo;
Serial.print("What is ");
Serial.print(numOne, DEC);
Serial.print(" x ");
Serial.print(numTwo, DEC);
Serial.println(" ?");
do{}
while(Serial.available() <= 0);
if(Serial.available() > 0){
do{
guess*=10;
guess += Serial.read() - 48;
delay(10);
}
while (Serial.available() > 0);
Serial.println(guess);
}
if(guess == answer)
{
pos -=18;
myservo.write(pos);
Serial.println("CORRECT!");
if(pos <= 0 )
{ Serial.println("YOU WON THE GAME!");
myservo.write(180);
delay(500);
myservo.write(0);
delay(500);
myservo.write(180);
delay(500);
myservo.write(0);
delay(500);
myservo.write(180);
delay(500);
pos= 180;
}
}
if (guess != answer){
pos += 36;
if (pos > 180) pos = 180;
myservo.write(pos);
Serial.println("YOU FAIL AT MATH (INCORRECT)");
}
}