Words

Dependencies:   4DGL-uLCD-SE PinDetect SDFileSystem mbed

Files at this revision

API Documentation at this revision

Comitter:
apaks180
Date:
Thu Mar 02 19:45:19 2017 +0000
Parent:
0:0072ee664a9b
Commit message:
Final version

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 0072ee664a9b -r 3cf69c15ada7 main.cpp
--- a/main.cpp	Thu Mar 02 11:35:32 2017 +0000
+++ b/main.cpp	Thu Mar 02 19:45:19 2017 +0000
@@ -22,7 +22,7 @@
     m_w = 18000 * (m_w & 65535) + (m_w >>16);
     return ((m_z <<16) + m_w);
 }
-int generateSquare(int box[], int side)
+int generateSquare(int box[], int side) //makes a square shape
 {
     int loc = abs(((int)rnd()))%18;
     while(box[loc]==1) {
@@ -43,7 +43,7 @@
     uLCD.filled_rectangle(x1, y1, x2, y2, color);
     return loc;
 }
-int generateTriangle(int box[], int side)
+int generateTriangle(int box[], int side) //makes a triangle shape
 {
     int loc = abs(((int)rnd()))%18;
     while(box[loc]==1) {
@@ -66,7 +66,7 @@
     uLCD.triangle(x1, y1, x2, y2, x3, y3, color);
     return loc;
 }
-int generateCircle(int box[], int side)
+int generateCircle(int box[], int side) //makes a circle shape
 {
     int loc = abs(((int)rnd()))%18;
     while(box[loc]==1) {
@@ -85,7 +85,7 @@
     uLCD.filled_circle(x, y, size, color);
     return loc;
 }
-string logData(int nT, int nC, int time, bool correct, FILE *fp)
+string logData(int nT, int nC, int time, bool correct, FILE *fp) //logs data to file AND prints to screen
 {
     std::ostringstream s;
     s << "Trial Number: " << nT << endl;
@@ -102,9 +102,11 @@
 }
 int main()
 {
+    //startup screen
     uLCD.display_control(PORTRAIT);
     uLCD.cls();
     uLCD.printf("Hello Friendly    Lemur!");
+    //super mario
     mySpeaker.PlayNote(660,.1,0.1);
     mySpeaker.PlayNote(0,.15,0.1);
     mySpeaker.PlayNote(660,.1,0.1);
@@ -157,7 +159,7 @@
     FILE *fp = fopen("/sd/mydir/LemurResults.txt", "w");
     leftButton.mode(PullUp);
     rightButton.mode(PullUp);
-    reset.mode(PullUp);
+    reset.mode(PullUp);             //some random variables that will be needed later (escaping from loops, keeping track of score, etc
     bool runTests = true;
     bool getoutoutside = false;
     bool getoutinside= false;
@@ -173,7 +175,7 @@
     while(runTests) {
         numTrials++;
         uLCD.rectangle(0, 0, 59, 120, WHITE);
-        uLCD.rectangle(68, 0, 127, 120, WHITE);
+        uLCD.rectangle(68, 0, 127, 120, WHITE);         //basic setup completed every time
         int boxL[18] = {};
         int boxR[18] = {};
 //15 is max number of circles
@@ -182,11 +184,11 @@
         while((leftNum==rightNum)||(leftNum==rightNum-1)||(leftNum==rightNum+1)||(leftNum==rightNum-2)||(leftNum==rightNum+2)) {
             rightNum=(abs((int)rnd())%14)+1;
         }
-        bool answer = false; //false=left side greater
-        if(leftNum<rightNum) {
-            answer = 1;   //true= right side greater
+        bool answer = false; //false=left side less
+        if(leftNum>rightNum) {
+            answer = 1;   //true= right side less
         }
-        for(int i = 0; i<leftNum; i++) {
+        for(int i = 0; i<leftNum; i++) {            //these loops place the already determined number of random shapes
             int choose = abs((int)rnd())%3;
             int newSpot = -1;
             if(choose==1)
@@ -208,7 +210,7 @@
                 newSpot = generateCircle(boxR, 1);
             boxR[newSpot] = 1;
         }
-        while(!getoutinside) {
+        while(!getoutinside) {          //lemur chooses which has fewer
             t.start();
             if(!leftButton) {
                 getoutinside=true;
@@ -228,14 +230,14 @@
                 t.stop();
             }
         }
-        int time = t.read_ms();
+        int time = t.read_ms();     //collect results, send it to logData function
         t.reset();
         getoutinside=false;
         wait(.25);
         uLCD.cls();
         string str = logData(numTrials, numCorrect, time, isCorrect, fp);
         uLCD.printf(str.c_str());
-        while(!getoutoutside) {
+        while(!getoutoutside) {         //check if lemur is supposed to continue (third button)
             if(!reset) {
                 getoutoutside=true;
                 runTests = false;
@@ -244,17 +246,12 @@
                 getoutoutside=true;
             }
         }
-        isCorrect = false;
+        isCorrect = false;          //reset variables
         getoutoutside = false;
         uLCD.cls();
     }
-    uLCD.printf("Goodbye, thanks for testing!");
+    uLCD.printf("Goodbye, thanks for testing!");    //black screen, close file
     wait(4);
     uLCD.cls();
     fclose(fp);
 }//end main
-
-
-
-
-