@@ 66,31 66,10 @@ byte qaCounter = 0;
// Remote-command variabes
const unsigned long remoteSwitchScroll = 0x1fe48b7;
const unsigned long remotePause = 0x1fee817;
-
-
-// Questions and answers
-char buffer[256]; // Maximum length of any question or answer.
-
-const char q_0[] PROGMEM = "What is the number of electrons going through the normal section of a wire whose current is 0.2 A during 16 s?";
-const char a_00[] PROGMEM = "Answer 1: 10^16";
-const char a_01[] PROGMEM = "Answer 2: 10^19";
-const char a_02[] PROGMEM = "Answer 3: 1.6 * 10^19";
-const char a_03[] PROGMEM = "Answer 4: 2.0 * 10^19";
-
-const char q_1[] PROGMEM = "A particle's trajectory is given by the parametric equations x = t, y = t^2 / 2. What is its curvature radius?";
-const char a_10[] PROGMEM = "Answer 1: (1+t^2)^(3/2)";
-const char a_11[] PROGMEM = "Answer 2: (1+t^3)^(1/2)";
-const char a_12[] PROGMEM = "Answer 3: (1+t)^(3/2)";
-const char a_13[] PROGMEM = "Answer 4: (1+t)^(1/2)";
-
-const char* const qa[] PROGMEM = {q_0, a_00, a_01, a_02, a_03, q_1, a_10, a_11, a_12, a_13};
-
-const byte numberOfQuestions = sizeof(qa)/10;
-
-char* getQA(byte qaNumber) {
- strcpy_P(buffer, (char*)pgm_read_word(&(qa[qaNumber])));
- return buffer;
-}
+const unsigned long remoteOne = 0x1fe807f;
+const unsigned long remoteTwo = 0x1fe40bf;
+const unsigned long remoteThree = 0x1fec03f;
+const unsigned long remoteFour = 0x1fe20df;
// Scrolling class
@@ 195,6 174,72 @@ class Scroller {
};
+// Questions and answers
+char buffer[256]; // Maximum length of any question or answer.
+
+const char q_0[] PROGMEM = "What is the number of electrons going through the normal section of a wire whose current is 0.2 A during 16 s?";
+const char a_00[] PROGMEM = "Answer 1: 10^16";
+const char a_01[] PROGMEM = "Answer 2: 10^19";
+const char a_02[] PROGMEM = "Answer 3: 1.6 * 10^19";
+const char a_03[] PROGMEM = "Answer 4: 2.0 * 10^19";
+
+const char q_1[] PROGMEM = "A particle's trajectory is given by the parametric equations x = t, y = t^2 / 2. What is its curvature radius?";
+const char a_10[] PROGMEM = "Answer 1: (1+t^2)^(3/2)";
+const char a_11[] PROGMEM = "Answer 2: (1+t^3)^(1/2)";
+const char a_12[] PROGMEM = "Answer 3: (1+t)^(3/2)";
+const char a_13[] PROGMEM = "Answer 4: (1+t)^(1/2)";
+
+const char* const qa[] PROGMEM = {q_0, a_00, a_01, a_02, a_03, q_1, a_10, a_11, a_12, a_13};
+
+const byte correctAnswers[] = {3, 0};
+
+const byte numberOfQuestions = sizeof(qa)/10;
+
+char* getQA(byte qaNumber) {
+ strcpy_P(buffer, (char*)pgm_read_word(&(qa[qaNumber])));
+ return buffer;
+}
+
+Scroller currentQA(getQA(qaCounter), 'H');
+
+void isCorrect(byte ans) {
+ unsigned short confirmationDelay = 1000;
+ if (ans == correctAnswers[questionCounter]) {
+ questionCounter++;
+ if (questionCounter >= numberOfQuestions) {
+ questionCounter = 0;
+ }
+ qaCounter = 5*questionCounter;
+ currentQA.reset(getQA(qaCounter));
+ #ifdef _DEBUG
+ Serial.println(F("Correct answer"));
+ #endif
+ lcd.clear();
+ lcd.print(F("Correct!"));
+ lcd.setCursor(0,1);
+ lcd.print(F("Go for the next!"));
+ tone(8, 392, 160);
+ delay(160);
+ tone(8, 523, 400);
+ delay(confirmationDelay);
+ lcd.clear();
+ } else {
+ #ifdef _DEBUG
+ Serial.println(F("Wrong answer"));
+ #endif
+ lcd.clear();
+ lcd.print(F("Wrong answer..."));
+ lcd.setCursor(0,1);
+ lcd.print(F("Keep trying!"));
+ tone(8, 196, 160);
+ delay(160);
+ tone(8, 65, 400);
+ delay(confirmationDelay);
+ lcd.clear();
+ }
+}
+
+
// Interruption-related functions
void detectMotion() {
motion = true;
@@ 212,9 257,6 @@ void updateActiveMillis() {
-// Set-up
-Scroller currentQA(getQA(qaCounter), 'H');
-
void setup() {
pinMode(motionPin, INPUT);
attachInterrupt(digitalPinToInterrupt(motionPin), detectMotion, RISING);
@@ 280,7 322,7 @@ void loop() {
case 4:
lcd.backlight();
lcd.setCursor(0, 0);
- lcd.print("Hello!");
+ lcd.print(F("Hello!"));
screenStep = 2000;
screenCounter++;
prevScreenMillis = millis();
@@ 305,19 347,19 @@ void loop() {
if (!(currentQA.completelyDisplayed)) {
currentQA.scroll();
#ifdef _DEBUG
- Serial.println("scroll");
+ Serial.println(F("Scrolling message"));
#endif
} else {
qaCounter++;
if (qaCounter >= 5*(questionCounter+1)) {
qaCounter = 5*questionCounter;
#ifdef _DEBUG
- Serial.println("qaCounter overflow");
+ Serial.println(F("Variable qaCounter overflowed > restarted"));
#endif
}
currentQA.reset(getQA(qaCounter));
#ifdef _DEBUG
- Serial.println("QAreset");
+ Serial.println(F("Scrolling class reset with new message"));
#endif
}
if (irrecv.decode(&results)) {
@@ 330,6 372,22 @@ void loop() {
currentQA.pauseOrResume();
updateActiveMillis();
break;
+ case remoteOne:
+ isCorrect(0);
+ updateActiveMillis();
+ break;
+ case remoteTwo:
+ isCorrect(1);
+ updateActiveMillis();
+ break;
+ case remoteThree:
+ isCorrect(2);
+ updateActiveMillis();
+ break;
+ case remoteFour:
+ isCorrect(3);
+ updateActiveMillis();
+ break;
}
irrecv.resume();
}