Miniproject of ECE4180

Dependencies:   4DGL-uLCD-SE mbed-rtos mbed

Revision:
2:346250dedcb6
Parent:
1:9465d72db54f
--- a/main.cpp	Mon Mar 09 22:04:56 2015 +0000
+++ b/main.cpp	Wed Mar 11 21:11:38 2015 +0000
@@ -2,6 +2,8 @@
 #include "rtos.h"
 #include "uLCD_4DGL.h"
 #include <vector>
+#include <stdlib.h>
+#include <time.h>
 
 DigitalIn yes(p5);
 DigitalIn no(p6);
@@ -47,8 +49,8 @@
     bool flag = false;
     int response = -1;
     int score = 0;
-    int time;
-    int* timePointer = &time;
+    int time_count;
+    int* timePointer = &time_count;
     int question_no = 0;
     bool endFlag = false;
     char* question = (char*) malloc(sizeof(char) * 150+1);;
@@ -82,6 +84,7 @@
             endFlag = true;
             break;
         }
+        srand(time(NULL));
         randind = (rand() % total_no_questions);
         total_no_questions--;
         rand_no = question_inds[randind];
@@ -125,10 +128,10 @@
         lcd.printf("No");
         lcd.locate(0,8);
         lcd.printf("%02d out of %02d", question_no, max_question_no);
-        time = 10;
+        time_count = 10;
         Thread timerr(timer, (void *) timePointer);
         wait(0.1);
-        while (time >= 0 && flag == false) {
+        while (time_count >= 0 && flag == false) {
             if (yes == true && no == true) {}
             else if (yes == true) {
                 flag = true;
@@ -137,7 +140,7 @@
                 flag = true;
                 response = 0;
             }
-            if (time == 0) {flag = true; response = -1;}
+            if (time_count == 0) {flag = true; response = -1;}
         }
         timerr.terminate();
         if (response == 1) {