Tianli Yu
Created March 3, 2020 © GPL3+

Build Your Own Quiz Robot with MoonBot

Build a robot that can give quiz questions to kids. Keep them engaged and learn something new.

IntermediateFull instructions provided1 hour1
Build Your Own Quiz Robot with MoonBot

Things used in this project

Hardware components

Morpx MoonBot Kit
×1
LEGO Technic Pieces
4 long beams only
×1

Software apps and online services

Mixly Arduino Block Programming Wrapper

Story

Read more

Schematics

Mixly Code

Code

QuizBot C code

C/C++
Note that this code is generated from mixly with slight modifications.
#include <Arduino.h>
#line 1 "quizbot3.cpp"
#include <MoonBot.h>
#include <MuVisionSensor.h>

volatile int head_angle;
volatile int state;
volatile int STATE_START;
volatile int STATE_QUIZ;
volatile int STATE_RESULT;
volatile int HEAD_ANGLE_UPPER_LIMIT;
volatile int HEAD_ANGLE_LOWER_LIMIT;
MuVisionSensor MU0(0x60);
volatile int turn_direction;
volatile int left_arm;
volatile int right_arm;
volatile long start_time;
volatile int angle1h;
volatile int angle1l;
volatile int angle2h;
volatile int angle2l;
volatile int angle3h;
volatile int angle3l;
volatile int answer;
volatile int question_index;
volatile boolean correct;
volatile boolean found_dup;
volatile int score;
volatile int led_r;
volatile int led_g;
volatile int led_b;

#line 31 "quizbot3.cpp"
void RunStart();
#line 50 "quizbot3.cpp"
void TrackPepole(int delay2);
#line 88 "quizbot3.cpp"
void RandomAction(long end_time, int rand_seed);
#line 118 "quizbot3.cpp"
void MoveLeftHand(int ms);
#line 126 "quizbot3.cpp"
void MoveRightHand(int ms);
#line 134 "quizbot3.cpp"
void LiftLeftHand(int ms);
#line 147 "quizbot3.cpp"
void RunResult();
#line 229 "quizbot3.cpp"
void LiftRightHand(int ms);
#line 242 "quizbot3.cpp"
void dance3();
#line 279 "quizbot3.cpp"
void dance8();
#line 319 "quizbot3.cpp"
void dance5();
#line 355 "quizbot3.cpp"
void dance_action1();
#line 409 "quizbot3.cpp"
void dancing();
#line 431 "quizbot3.cpp"
void eye_white_1();
#line 448 "quizbot3.cpp"
void Nod(int duration, int center);
#line 455 "quizbot3.cpp"
void ResetScore();
#line 462 "quizbot3.cpp"
void TankBaseTurn(int speed, int ms);
#line 469 "quizbot3.cpp"
void TankBaseShake(int speed, int ms);
#line 487 "quizbot3.cpp"
void eye_white_2();
#line 504 "quizbot3.cpp"
boolean ReadResult(int i);
#line 557 "quizbot3.cpp"
void BlinkCorrect();
#line 584 "quizbot3.cpp"
void BlinkWrong();
#line 763 "quizbot3.cpp"
void PlayQuestion(int i);
#line 965 "quizbot3.cpp"
void BlinkEye(int ms);
#line 1093 "quizbot3.cpp"
void BlinkLeft(int ms);
#line 1221 "quizbot3.cpp"
void dance4();
#line 1263 "quizbot3.cpp"
void BlinkRight(int ms);
#line 1391 "quizbot3.cpp"
void dance6();
#line 1432 "quizbot3.cpp"
void RunQuiz();
#line 1454 "quizbot3.cpp"
int GradeQuestion(int question_i, int ans);
#line 1489 "quizbot3.cpp"
int GetRandomNoRepeat(int qi);
#line 1505 "quizbot3.cpp"
void ShowProgress();
#line 1530 "quizbot3.cpp"
void CalcScore();
#line 1540 "quizbot3.cpp"
void ShowScore();
#line 1598 "quizbot3.cpp"
void SpeakNumber(int x);
#line 1643 "quizbot3.cpp"
void setup();
#line 1741 "quizbot3.cpp"
void loop();
#line 31 "quizbot3.cpp"
void RunStart() {
  while(MU0.VisionBegin(VISION_BODY_DETECT) != MU_OK);
  TrackPepole(1000);
  speaker.play("STAR");
  while (!(digitalRead(moonbotPortToPin(kPort3, kPortPin1)))) {
    BlinkLeft(200);
    if (digitalRead(moonbotPortToPin(kPort7, kPortPin1))) {
      speaker.play("STAR");

    } else {
      TrackPepole(200);

    }
  }
  randomSeed(millis());
  state = STATE_QUIZ;
  while(MU0.VisionEnd(VISION_BODY_DETECT) != MU_OK);
}

void TrackPepole(int delay2) {
  start_time = millis();
  while (millis() < start_time + delay2) {
    if (MU0.GetValue(VISION_BODY_DETECT, kStatus)) {
      if (MU0.GetValue(VISION_BODY_DETECT, kXValue) < 45) {
        Motor1.writeRpm(30);
        Motor2.writeRpm(-30);

      } else if (MU0.GetValue(VISION_BODY_DETECT, kXValue) > 55) {
        Motor1.writeRpm(-30);
        Motor2.writeRpm(30);
      } else {
        TankBase.stop();
        if (MU0.GetValue(VISION_BODY_DETECT, kYValue) < 45) {
          head_angle = constrain(m_servo[kServo3].read() - 3, HEAD_ANGLE_UPPER_LIMIT, HEAD_ANGLE_LOWER_LIMIT);
          m_servo[kServo3].write(head_angle);

        } else if (MU0.GetValue(VISION_BODY_DETECT, kYValue) > 55) {
          head_angle = constrain(m_servo[kServo3].read() + 3, HEAD_ANGLE_UPPER_LIMIT, HEAD_ANGLE_LOWER_LIMIT);
          m_servo[kServo3].write(head_angle);
        }

      }
      moonbot_eyes.setBrightness(60);

    } else {
      moonbot_eyes.setBrightness(30);

    }
  }
  TankBase.stop();
}

uint32_t m_beat = 500;
int score_list[]={0,0,0,0,0,0,0,0,0,0,0,0};

int question_list[]={0,0,0,0,0,0,0,0,0,0,0,0};

void RandomAction(long end_time, int rand_seed) {
  randomSeed(rand_seed);
  while (millis() < end_time - 500) {
    switch (random(1, 8)) {
     case 1:
      Nod(500, 75 + random(-10, 10));
      break;
     case 2:
      MoveLeftHand(500);
      break;
     case 3:
      MoveRightHand(500);
      break;
     case 4:
      TankBaseTurn(20, 0);
      Nod(500, 75 + random(-10, 10));
      TankBase.stop();
      break;
     case 5:
      BlinkEye(500);
      break;
     default:
      Nod(500, 75 + random(-10, 10));
      break;
    }
  }
  while (millis() < end_time) {
  }
}

void MoveLeftHand(int ms) {
  left_arm = m_servo[kServo1].read();
  m_servo[kServo1].write(80);
  delay(ms/2);
  m_servo[kServo1].write(left_arm);
  delay(ms/2);
}

void MoveRightHand(int ms) {
  right_arm = m_servo[kServo4].read();
  m_servo[kServo4].write(100);
  delay(ms/2);
  m_servo[kServo4].write(right_arm);
  delay(ms/2);
}

void LiftLeftHand(int ms) {
  left_arm = m_servo[kServo1].read();
  m_servo[kServo1].write(10);
  delay(ms/4);
  m_servo[kServo1].write(30);
  delay(ms/4);
  m_servo[kServo1].write(10);
  delay(ms/4);
  m_servo[kServo1].write(30);
  delay(ms/4);
  m_servo[kServo1].write(left_arm);
}

void RunResult() {
  while(MU0.VisionBegin(VISION_BODY_DETECT) != MU_OK);
  speaker.play("GREA");
  TrackPepole(3000);
  speaker.play("SOFU");
  TrackPepole(2000);
  ShowScore();
  speaker.play("REST");
  while (true) {
    if (digitalRead(moonbotPortToPin(kPort3, kPortPin1))) {
      delay(50);
      if (digitalRead(moonbotPortToPin(kPort7, kPortPin1))) {
        state = STATE_START;
        break;

      } else {
        ShowScore();
        speaker.play("REST");

      }

    } else if (digitalRead(moonbotPortToPin(kPort7, kPortPin1))) {
      delay(50);
      if (digitalRead(moonbotPortToPin(kPort3, kPortPin1))) {
        state = STATE_START;
        break;

      } else {
        ShowScore();
        speaker.play("REST");

      }
    }
    TrackPepole(300);
  }
  while(MU0.VisionEnd(VISION_BODY_DETECT) != MU_OK);
  for (size_t i = 0; i < kServoNum; ++i) { m_servo[i].power(0); }
  {//eyes blink
      unsigned int action_delay = 30;
      moonbot_eyes.setPixelColor(0, 0);
      moonbot_eyes.setPixelColor(6, 0);
      moonbot_eyes.show();
      delay(action_delay);
      moonbot_eyes.setPixelColor(1, 0);
      moonbot_eyes.setPixelColor(5, 0);
      moonbot_eyes.setPixelColor(7, 0);
      moonbot_eyes.setPixelColor(11, 0);
      moonbot_eyes.show();
      delay(action_delay);
      moonbot_eyes.setPixelColor(2, 0);
      moonbot_eyes.setPixelColor(4, 0);
      moonbot_eyes.setPixelColor(8, 0);
      moonbot_eyes.setPixelColor(10, 0);
      moonbot_eyes.show();
      delay(action_delay);
      moonbot_eyes.setPixelColor(3, 0);
      moonbot_eyes.setPixelColor(9, 0);
      moonbot_eyes.show();
      delay(action_delay);
      moonbot_eyes.setPixelColor(3, 0, 0xFF, 0xFF);
      moonbot_eyes.setPixelColor(9, 0, 0xFF, 0xFF);
      moonbot_eyes.show();
      delay(action_delay);
      moonbot_eyes.setPixelColor(2, 0, 0xFF, 0xFF);
      moonbot_eyes.setPixelColor(4, 0, 0xFF, 0xFF);
      moonbot_eyes.setPixelColor(8, 0, 0xFF, 0xFF);
      moonbot_eyes.setPixelColor(10, 0, 0xFF, 0xFF);
      moonbot_eyes.show();
      delay(action_delay);
      moonbot_eyes.setPixelColor(1, 0, 0xFF, 0xFF);
      moonbot_eyes.setPixelColor(5, 0, 0xFF, 0xFF);
      moonbot_eyes.setPixelColor(7, 0, 0xFF, 0xFF);
      moonbot_eyes.setPixelColor(11, 0, 0xFF, 0xFF);
      moonbot_eyes.show();
      delay(action_delay);
      moonbot_eyes.setPixelColor(0, 0, 0xFF, 0xFF);
      moonbot_eyes.setPixelColor(6, 0, 0xFF, 0xFF);
      moonbot_eyes.show();
  }
  for (size_t i = 0; i < kServoNum; ++i) { m_servo[i].power(1); }
}

void LiftRightHand(int ms) {
  right_arm = m_servo[kServo4].read();
  m_servo[kServo4].write(170);
  delay(ms/4);
  m_servo[kServo4].write(150);
  delay(ms/4);
  m_servo[kServo4].write(170);
  delay(ms/4);
  m_servo[kServo4].write(150);
  delay(ms/4);
  m_servo[kServo4].write(right_arm);
}

void dance3() {
  speaker.play("1043");
  TankBase.turnLeft(15, 30);
  while(TankBase.read(kLeftMotor) && TankBase.read(kRightMotor));
  delay(100);
  for (int i = 1; i <= 2; i = i + (1)) {
    dance_action1();
    delay(120);
  }
  for (int i = 1; i <= 4; i = i + (1)) {
    dance_action1();
  }
  TankBase.turnRight(15, 30);
  while(TankBase.read(kLeftMotor) && TankBase.read(kRightMotor));
  delay(100);
  dance_action1();
  delay(400);
  dance_action1();
  LED.setPixelColor(0, 0x000000);
  LED.setPixelColor(1, 0x000000);
  LED.show();
  moonbot_eyes.setPixelColor(0, 0x000000);
  moonbot_eyes.setPixelColor(1, 0x000000);
  moonbot_eyes.setPixelColor(2, 0x000000);
  moonbot_eyes.setPixelColor(3, 0x000000);
  moonbot_eyes.setPixelColor(4, 0x000000);
  moonbot_eyes.setPixelColor(5, 0x000000);
  moonbot_eyes.setPixelColor(6, 0x000000);
  moonbot_eyes.setPixelColor(7, 0x000000);
  moonbot_eyes.setPixelColor(8, 0x000000);
  moonbot_eyes.setPixelColor(9, 0x000000);
  moonbot_eyes.setPixelColor(10, 0x000000);
  moonbot_eyes.setPixelColor(11, 0x000000);
  moonbot_eyes.show();
  delay(200);
}

void dance8() {
  speaker.play("1048");
  dance_action1();
  TankBase.turnLeft(15, 30);
  while(TankBase.read(kLeftMotor) && TankBase.read(kRightMotor));
  delay(100);
  for (int i = 1; i <= 2; i = i + (1)) {
    dance_action1();
  }
  delay(150);
  for (int i = 1; i <= 3; i = i + (1)) {
    dance_action1();
    delay(100);
  }
  for (int i = 1; i <= 2; i = i + (1)) {
    dance_action1();
  }
  TankBase.turnRight(15, 30);
  while(TankBase.read(kLeftMotor) && TankBase.read(kRightMotor));
  delay(100);
  dance_action1();
  LED.setPixelColor(0, 0x000000);
  LED.setPixelColor(1, 0x000000);
  LED.show();
  moonbot_eyes.setPixelColor(0, 0x000000);
  moonbot_eyes.setPixelColor(1, 0x000000);
  moonbot_eyes.setPixelColor(2, 0x000000);
  moonbot_eyes.setPixelColor(3, 0x000000);
  moonbot_eyes.setPixelColor(4, 0x000000);
  moonbot_eyes.setPixelColor(5, 0x000000);
  moonbot_eyes.setPixelColor(6, 0x000000);
  moonbot_eyes.setPixelColor(7, 0x000000);
  moonbot_eyes.setPixelColor(8, 0x000000);
  moonbot_eyes.setPixelColor(9, 0x000000);
  moonbot_eyes.setPixelColor(10, 0x000000);
  moonbot_eyes.setPixelColor(11, 0x000000);
  moonbot_eyes.show();
  delay(100);
}

void dance5() {
  speaker.play("1045");
  dance_action1();
  TankBase.turnLeft(15, 30);
  while(TankBase.read(kLeftMotor) && TankBase.read(kRightMotor));
  delay(100);
  dance_action1();
  delay(150);
  for (int i = 1; i <= 2; i = i + (1)) {
    dance_action1();
  }
  TankBase.turnRight(15, 30);
  while(TankBase.read(kLeftMotor) && TankBase.read(kRightMotor));
  delay(100);
  for (int i = 1; i <= 9; i = i + (1)) {
    dance_action1();
  }
  LED.setPixelColor(0, 0x000000);
  LED.setPixelColor(1, 0x000000);
  LED.show();
  moonbot_eyes.setPixelColor(0, 0x000000);
  moonbot_eyes.setPixelColor(1, 0x000000);
  moonbot_eyes.setPixelColor(2, 0x000000);
  moonbot_eyes.setPixelColor(3, 0x000000);
  moonbot_eyes.setPixelColor(4, 0x000000);
  moonbot_eyes.setPixelColor(5, 0x000000);
  moonbot_eyes.setPixelColor(6, 0x000000);
  moonbot_eyes.setPixelColor(7, 0x000000);
  moonbot_eyes.setPixelColor(8, 0x000000);
  moonbot_eyes.setPixelColor(9, 0x000000);
  moonbot_eyes.setPixelColor(10, 0x000000);
  moonbot_eyes.setPixelColor(11, 0x000000);
  moonbot_eyes.show();
  delay(200);
}

void dance_action1() {
  LED.setBrightness(100);
  switch (random(1, 4)) {
   case 1:
    angle1h = 120;
    angle1l = 90;
    angle2h = 120;
    angle2l = 90;
    angle3h = 120;
    angle3l = 90;
    break;
   case 2:
    angle1h = 120;
    angle1l = 90;
    angle2h = 90;
    angle2l = 120;
    angle3h = 120;
    angle3l = 90;
    break;
   case 3:
    angle1h = 140;
    angle1l = 120;
    angle2h = 140;
    angle2l = 120;
    angle3h = 140;
    angle3l = 120;
    break;
   case 4:
    angle1h = 120;
    angle1l = 140;
    angle2h = 140;
    angle2l = 120;
    angle3h = 110;
    angle3l = 80;
    break;
  }
  m_servo[kServo1].write(angle1h);
  m_servo[kServo4].write(angle2h);
  m_servo[kServo3].write(angle3h);
  eye_white_2();
  LED.setPixelColor(0, 0xffffff);
  LED.setPixelColor(1, 0x000000);
  LED.show();
  delay(50);
  m_servo[kServo1].write(angle1l);
  m_servo[kServo4].write(angle2l);
  m_servo[kServo3].write(angle3l);
  eye_white_1();
  LED.setPixelColor(0, 0x000000);
  LED.setPixelColor(1, 0xffffff);
  LED.show();
  delay(70);
}

void dancing() {
  for (int i = 1; i <= 4; i = i + (1)) {
    switch (random(1, 6)) {
     case 1:
      dance3();
      break;
     case 2:
      dance4();
      break;
     case 3:
      dance5();
      break;
     case 4:
      dance6();
      break;
     case 5:
      dance8();
      break;
    }
  }
}

void eye_white_1() {
  moonbot_eyes.setBrightness(150);
  moonbot_eyes.setPixelColor(0, 0x000000);
  moonbot_eyes.setPixelColor(1, 0xffffff);
  moonbot_eyes.setPixelColor(2, 0x000000);
  moonbot_eyes.setPixelColor(3, 0xffffff);
  moonbot_eyes.setPixelColor(4, 0x000000);
  moonbot_eyes.setPixelColor(5, 0xffffff);
  moonbot_eyes.setPixelColor(6, 0x000000);
  moonbot_eyes.setPixelColor(7, 0xffffff);
  moonbot_eyes.setPixelColor(8, 0x000000);
  moonbot_eyes.setPixelColor(9, 0xffffff);
  moonbot_eyes.setPixelColor(10, 0x000000);
  moonbot_eyes.setPixelColor(11, 0xffffff);
  moonbot_eyes.show();
}

void Nod(int duration, int center) {
  m_servo[kServo3].write(center + 5);
  delay(duration / 2);
  m_servo[kServo3].write(center - 5);
  delay(duration / 2);
}

void ResetScore() {
  for (int i = 1; i <= 12; i = i + (1)) {
    score_list[(int)(i - 1)] = -1;
    question_list[(int)(i - 1)] = -1;
  }
}

void TankBaseTurn(int speed, int ms) {
  Motor1.writeRpm(turn_direction * speed);
  Motor2.writeRpm(-turn_direction * speed);
  delay(ms);
  turn_direction = -turn_direction;
}

void TankBaseShake(int speed, int ms) {
  Motor1.writeRpm(speed);
  Motor2.writeRpm(-speed);
  delay(ms/6);
  Motor1.writeRpm(-speed);
  Motor2.writeRpm(speed);
  delay(ms/6);
  delay(ms/6);
  Motor1.writeRpm(speed);
  Motor2.writeRpm(-speed);
  delay(ms/6);
  delay(ms/6);
  Motor1.writeRpm(-speed);
  Motor2.writeRpm(speed);
  delay(ms/6);
  TankBase.stop();
}

void eye_white_2() {
  moonbot_eyes.setBrightness(150);
  moonbot_eyes.setPixelColor(0, 0xffffff);
  moonbot_eyes.setPixelColor(1, 0x000000);
  moonbot_eyes.setPixelColor(2, 0xffffff);
  moonbot_eyes.setPixelColor(3, 0x000000);
  moonbot_eyes.setPixelColor(4, 0xffffff);
  moonbot_eyes.setPixelColor(5, 0x000000);
  moonbot_eyes.setPixelColor(6, 0xffffff);
  moonbot_eyes.setPixelColor(7, 0x000000);
  moonbot_eyes.setPixelColor(8, 0xffffff);
  moonbot_eyes.setPixelColor(9, 0x000000);
  moonbot_eyes.setPixelColor(10, 0xffffff);
  moonbot_eyes.setPixelColor(11, 0x000000);
  moonbot_eyes.show();
}

boolean ReadResult(int i) {
  while(MU0.VisionBegin(VISION_NUM_CARD_DETECT) != MU_OK);
  while (true) {
    if (MU0.GetValue(VISION_NUM_CARD_DETECT, kStatus)) {
      if ((MU0.GetValue(VISION_NUM_CARD_DETECT, kLabel) == 1)) {
        {//tone play
            tone(MOONBOT_PIN_BUZZER_SIG, NOTE_A4);
            delay(m_beat*BEAT_FRACTION_WHOLE/BEAT_FRACTION_WHOLE);
            noTone(MOONBOT_PIN_BUZZER_SIG);
        }
        answer = 1;
        break;

      } else if ((MU0.GetValue(VISION_NUM_CARD_DETECT, kLabel) == 2)) {
        {//tone play
            tone(MOONBOT_PIN_BUZZER_SIG, NOTE_A4);
            delay(m_beat*BEAT_FRACTION_WHOLE/BEAT_FRACTION_WHOLE);
            noTone(MOONBOT_PIN_BUZZER_SIG);
        }
        answer = 2;
        break;
      } else if ((MU0.GetValue(VISION_NUM_CARD_DETECT, kLabel) == 3)) {
        {//tone play
            tone(MOONBOT_PIN_BUZZER_SIG, NOTE_A4);
            delay(m_beat*BEAT_FRACTION_WHOLE/BEAT_FRACTION_WHOLE);
            noTone(MOONBOT_PIN_BUZZER_SIG);
        }
        answer = 3;
        break;
      } else if ((MU0.GetValue(VISION_NUM_CARD_DETECT, kLabel) == 4)) {
        {//tone play
            tone(MOONBOT_PIN_BUZZER_SIG, NOTE_A4);
            delay(m_beat*BEAT_FRACTION_WHOLE/BEAT_FRACTION_WHOLE);
            noTone(MOONBOT_PIN_BUZZER_SIG);
        }
        answer = 4;
        break;
      }

    } else if (digitalRead(moonbotPortToPin(kPort3, kPortPin1)) && digitalRead(moonbotPortToPin(kPort7, kPortPin1))) {
      state = STATE_START;
      while(MU0.VisionEnd(VISION_NUM_CARD_DETECT) != MU_OK);
      if (true) {
        return true;
      }
    } else if (digitalRead(moonbotPortToPin(kPort3, kPortPin1)) || digitalRead(moonbotPortToPin(kPort7, kPortPin1))) {
      PlayQuestion(i);
    }
  }
  while(MU0.VisionEnd(VISION_NUM_CARD_DETECT) != MU_OK);
  return false;
}

void BlinkCorrect() {
  switch (random(1, 4)) {
   case 1:
    speaker.play("YS01");
    speaker.play("YS01");
    break;
   case 2:
    speaker.play("YS01");
    speaker.play("YS02");
    break;
   case 3:
    speaker.play("YS03");
    speaker.play("YS03");
    break;
  }
  for (int i = 1; i <= 4; i = i + (1)) {
    LED.setPixelColor(0, 0x00ff00);
    LED.setPixelColor(1, 0x00ff00);
    LED.show();
    delay(160);
    LED.setPixelColor(0, 0x000000);
    LED.setPixelColor(1, 0x000000);
    LED.show();
    delay(160);
  }
}

void BlinkWrong() {
  switch (random(1, 4)) {
   case 1:
    speaker.play("NO01");
    break;
   case 2:
    speaker.play("NO02");
    break;
   case 3:
    speaker.play("NO03");
    break;
  }
  for (int i = 1; i <= 4; i = i + (1)) {
    LED.setPixelColor(0, 0xff0000);
    LED.setPixelColor(1, 0xff0000);
    LED.show();
    delay(160);
    LED.setPixelColor(0, 0x000000);
    LED.setPixelColor(1, 0x000000);
    LED.show();
    delay(160);
  }
  speaker.play("ANSW");
  delay(1000);
  switch (question_index) {
   case 1:
    speaker.play("QA01");
    break;
   case 2:
    speaker.play("QA02");
    break;
   case 3:
    speaker.play("QA03");
    break;
   case 4:
    speaker.play("QA04");
    break;
   case 5:
    speaker.play("QA05");
    break;
   case 6:
    speaker.play("QA06");
    break;
   case 7:
    speaker.play("QA07");
    break;
   case 8:
    speaker.play("QA08");
    break;
   case 9:
    speaker.play("QA09");
    break;
   case 10:
    speaker.play("QA10");
    break;
   case 11:
    speaker.play("QA11");
    break;
   case 12:
    speaker.play("QA12");
    break;
  }
  switch (question_index) {
   case 13:
    speaker.play("QA13");
    break;
   case 14:
    speaker.play("QA14");
    break;
   case 15:
    speaker.play("QA15");
    break;
   case 16:
    speaker.play("QA16");
    break;
   case 17:
    speaker.play("QA17");
    break;
   case 18:
    speaker.play("QA18");
    break;
   case 19:
    speaker.play("QA19");
    break;
   case 20:
    speaker.play("QA20");
    break;
   case 21:
    speaker.play("QA21");
    break;
   case 22:
    speaker.play("QA22");
    break;
   case 23:
    speaker.play("QA23");
    break;
   case 24:
    speaker.play("QA24");
    break;
  }
  switch (question_index) {
   case 25:
    speaker.play("QA25");
    break;
   case 26:
    speaker.play("QA36");
    break;
   case 27:
    speaker.play("QA27");
    break;
   case 28:
    speaker.play("QA28");
    break;
   case 29:
    speaker.play("QA29");
    break;
   case 30:
    speaker.play("QA30");
    break;
   case 31:
    speaker.play("QA31");
    break;
   case 32:
    speaker.play("QA32");
    break;
   case 33:
    speaker.play("QA33");
    break;
   case 34:
    speaker.play("QA34");
    break;
   case 35:
    speaker.play("QA35");
    break;
   case 36:
    speaker.play("QA36");
    break;
  }
  switch (question_index) {
   case 37:
    speaker.play("QA37");
    break;
   case 38:
    speaker.play("QA38");
    break;
   case 39:
    speaker.play("QA39");
    break;
   case 40:
    speaker.play("QA40");
    break;
   case 41:
    speaker.play("QA41");
    break;
   case 42:
    speaker.play("QA42");
    break;
   case 43:
    speaker.play("QA43");
    break;
   case 44:
    speaker.play("QA44");
    break;
   case 45:
    speaker.play("QA45");
    break;
   case 46:
    speaker.play("QA46");
    break;
   case 47:
    speaker.play("QA47");
    break;
   case 48:
    speaker.play("QA48");
    break;
  }
  RandomAction(millis() + 3000, millis());
}

void PlayQuestion(int i) {
  speaker.play("QUES");
  for (size_t i = 0; i < kServoNum; ++i) { m_servo[i].power(0); }
  {//eyes blink
      unsigned int action_delay = 30;
      moonbot_eyes.setPixelColor(0, 0);
      moonbot_eyes.setPixelColor(6, 0);
      moonbot_eyes.show();
      delay(action_delay);
      moonbot_eyes.setPixelColor(1, 0);
      moonbot_eyes.setPixelColor(5, 0);
      moonbot_eyes.setPixelColor(7, 0);
      moonbot_eyes.setPixelColor(11, 0);
      moonbot_eyes.show();
      delay(action_delay);
      moonbot_eyes.setPixelColor(2, 0);
      moonbot_eyes.setPixelColor(4, 0);
      moonbot_eyes.setPixelColor(8, 0);
      moonbot_eyes.setPixelColor(10, 0);
      moonbot_eyes.show();
      delay(action_delay);
      moonbot_eyes.setPixelColor(3, 0);
      moonbot_eyes.setPixelColor(9, 0);
      moonbot_eyes.show();
      delay(action_delay);
      moonbot_eyes.setPixelColor(3, 0, 0xFF, 0xFF);
      moonbot_eyes.setPixelColor(9, 0, 0xFF, 0xFF);
      moonbot_eyes.show();
      delay(action_delay);
      moonbot_eyes.setPixelColor(2, 0, 0xFF, 0xFF);
      moonbot_eyes.setPixelColor(4, 0, 0xFF, 0xFF);
      moonbot_eyes.setPixelColor(8, 0, 0xFF, 0xFF);
      moonbot_eyes.setPixelColor(10, 0, 0xFF, 0xFF);
      moonbot_eyes.show();
      delay(action_delay);
      moonbot_eyes.setPixelColor(1, 0, 0xFF, 0xFF);
      moonbot_eyes.setPixelColor(5, 0, 0xFF, 0xFF);
      moonbot_eyes.setPixelColor(7, 0, 0xFF, 0xFF);
      moonbot_eyes.setPixelColor(11, 0, 0xFF, 0xFF);
      moonbot_eyes.show();
      delay(action_delay);
      moonbot_eyes.setPixelColor(0, 0, 0xFF, 0xFF);
      moonbot_eyes.setPixelColor(6, 0, 0xFF, 0xFF);
      moonbot_eyes.show();
  }
  for (size_t i = 0; i < kServoNum; ++i) { m_servo[i].power(1); }
  delay(500);
  SpeakNumber(i);
  switch (question_index) {
   case 1:
    speaker.play("QZ01");
    break;
   case 2:
    speaker.play("QZ02");
    break;
   case 3:
    speaker.play("QZ03");
    break;
   case 4:
    speaker.play("QZ04");
    break;
   case 5:
    speaker.play("QZ05");
    break;
   case 6:
    speaker.play("QZ06");
    break;
   case 7:
    speaker.play("QZ07");
    break;
   case 8:
    speaker.play("QZ08");
    break;
   case 9:
    speaker.play("QZ09");
    break;
   case 10:
    speaker.play("QZ10");
    break;
   case 11:
    speaker.play("QZ11");
    break;
   case 12:
    speaker.play("QZ12");
    break;
  }
  switch (question_index) {
   case 13:
    speaker.play("QZ13");
    break;
   case 14:
    speaker.play("QZ14");
    break;
   case 15:
    speaker.play("QZ15");
    break;
   case 16:
    speaker.play("QZ16");
    break;
   case 17:
    speaker.play("QZ17");
    break;
   case 18:
    speaker.play("QZ18");
    break;
   case 19:
    speaker.play("QZ19");
    break;
   case 20:
    speaker.play("QZ20");
    break;
   case 21:
    speaker.play("QZ21");
    break;
   case 22:
    speaker.play("QZ22");
    break;
   case 23:
    speaker.play("QZ23");
    break;
   case 24:
    speaker.play("QZ24");
    break;
  }
  switch (question_index) {
   case 25:
    speaker.play("QZ25");
    break;
   case 26:
    speaker.play("QZ36");
    break;
   case 27:
    speaker.play("QZ27");
    break;
   case 28:
    speaker.play("QZ28");
    break;
   case 29:
    speaker.play("QZ29");
    break;
   case 30:
    speaker.play("QZ30");
    break;
   case 31:
    speaker.play("QZ31");
    break;
   case 32:
    speaker.play("QZ32");
    break;
   case 33:
    speaker.play("QZ33");
    break;
   case 34:
    speaker.play("QZ34");
    break;
   case 35:
    speaker.play("QZ35");
    break;
   case 36:
    speaker.play("QZ36");
    break;
...

This file has been truncated, please download it to see its full contents.

Credits

Tianli Yu

Tianli Yu

2 projects • 2 followers
Thanks to Morpx Team.

Comments