Whack a Mole game! Features: - LCD graphics display - Touch pad input - Speaker effects through a class D audio amplifier\ - A high score page maintained by the SD card file system - Analog noise used to seed random numbers

Dependencies:   4DGL-uLCD-SE SDFileSystem mbed

Fork of MPR121_Demo by jim hamblen

Revision:
3:dbae62823ec8
Parent:
2:d85c5ce4d397
Child:
4:4cb02cde783c
diff -r d85c5ce4d397 -r dbae62823ec8 main.cpp
--- a/main.cpp	Mon Mar 14 03:34:58 2016 +0000
+++ b/main.cpp	Mon Mar 14 04:26:32 2016 +0000
@@ -25,7 +25,6 @@
 #include <list>
 #include "uLCD_4DGL.h"
 #include <mpr121.h>
-#include "rtos.h"
 
 uLCD_4DGL lcd(p9, p10, p30); // tx, rx, reset
 
@@ -37,7 +36,6 @@
 
 // Create the interrupt receiver object on pin 26
 InterruptIn interrupt(p26);
-Mutex POS_MUTEX;
 // Setup the Serial to the PC for debugging
 Serial pc(USBTX, USBRX);
 
@@ -67,12 +65,30 @@
     int value=mpr121.read(0x00);
     value +=mpr121.read(0x01)<<8;
     // LED demo mod by J. Hamblen
-    POS_MUTEX.lock();
-    if (value==hole1&&pos1==1)
+    if (value==256&&pos1==1)
+    {
+        score++;
+    }
+        if (value==16&&pos2==1)
+    {
+        score++;
+    }
+        if (value==1&&pos3==1)
     {
         score++;
     }
-    POS_MUTEX.unlock();
+        if (value==512&&pos4==1)
+    {
+        score++;
+    }
+        if (value==32&&pos5==1)
+    {
+        score++;
+    }
+        if (value==2&&pos6==1)
+    {
+        score++;
+    }
     pc.printf("MPR value: %x \r\n", value);
     /*if (value == 1)
     {
@@ -195,14 +211,14 @@
         switch(state)
         {
             case 0:
-            POS_MUTEX.lock();
+            //POS_MUTEX.lock();
             pos1=1;
             pos2=0;
             pos3=0;
             pos4=0;
             pos5=0;
             pos6=0;
-            POS_MUTEX.unlock();
+            //POS_MUTEX.unlock();
             pc.printf("%i should be 0 \n\r",state);
 lcd.filled_circle(col1, row1 , rmole, fill);// 1
 lcd.filled_circle(col1, row2 , rmole, fill);
@@ -213,14 +229,14 @@
 lcd.filled_circle(col1, row1 , rmole, mole);
             break;
             case 1:
-            POS_MUTEX.lock();
+            //POS_MUTEX.lock();
             pos1=0;
             pos2=1;
             pos3=0;
             pos4=0;
             pos5=0;
             pos6=0;
-            POS_MUTEX.unlock();
+            //POS_MUTEX.unlock();
             pc.printf("%i should be 1 \n\r",state);
 lcd.filled_circle(col1, row1 , rmole, fill);// 2
 lcd.filled_circle(col1, row2 , rmole, fill);
@@ -231,14 +247,14 @@
 lcd.filled_circle(col2, row1 , rmole, mole);
             break;
             case 2:
-            POS_MUTEX.lock();
+            //POS_MUTEX.lock();
             pos1=0;
             pos2=0;
             pos3=1;
             pos4=0;
             pos5=0;
             pos6=0;
-            POS_MUTEX.unlock();
+            //POS_MUTEX.unlock();
             pc.printf("%i should be 2 \n\r",state);
             lcd.filled_circle(col1, row1 , rmole, fill);// 3
 lcd.filled_circle(col1, row2 , rmole, fill);
@@ -249,14 +265,14 @@
 lcd.filled_circle(col3, row1 , rmole, mole);
             break;
             case 3:
-            POS_MUTEX.lock();
+            //POS_MUTEX.lock();
             pos1=0;
             pos2=0;
             pos3=0;
             pos4=1;
             pos5=0;
             pos6=0;
-            POS_MUTEX.unlock();
+            //POS_MUTEX.unlock();
             pc.printf("%i should be 3 \n\r",state);
             lcd.filled_circle(col1, row1 , rmole, fill);// 4
 lcd.filled_circle(col1, row2 , rmole, fill);
@@ -267,14 +283,14 @@
 lcd.filled_circle(col1, row2 , rmole, mole);
             break;
             case 4:
-            POS_MUTEX.lock();
+            //POS_MUTEX.lock();
             pos1=0;
             pos2=0;
             pos3=0;
             pos4=0;
             pos5=1;
             pos6=0;
-            POS_MUTEX.unlock();
+            //POS_MUTEX.unlock();
             pc.printf("%i should be 4 \n\r",state);
             lcd.filled_circle(col1, row1 , rmole, fill);// 5
 lcd.filled_circle(col1, row2 , rmole, fill);
@@ -285,14 +301,14 @@
 lcd.filled_circle(col2, row2 , rmole, mole);
             break;
             case 5:
-            POS_MUTEX.lock();
+            //POS_MUTEX.lock();
             pos1=0;
             pos2=0;
             pos3=0;
             pos4=0;
             pos5=0;
             pos6=1;
-            POS_MUTEX.unlock();
+            //POS_MUTEX.unlock();
             pc.printf("%i should be 5 \n\r",state);
             
 lcd.filled_circle(col1, row1 , rmole, fill);// 6
@@ -304,14 +320,14 @@
 lcd.filled_circle(col2, row2 , rmole, mole);
             break;
             case 6:
-            POS_MUTEX.lock();
+            //POS_MUTEX.lock();
             pos1=0;
             pos2=1;
             pos3=0;
             pos4=0;
             pos5=0;
             pos6=1;
-            POS_MUTEX.unlock();
+            //POS_MUTEX.unlock();
             pc.printf("%i should be 6 \n\r",state);
             lcd.filled_circle(col1, row1 , rmole, fill);// 2,6
 lcd.filled_circle(col1, row2 , rmole, fill);
@@ -323,14 +339,14 @@
 lcd.filled_circle(col3, row2 , rmole, mole);
             break;
             case 7:
-            POS_MUTEX.lock();
+            //POS_MUTEX.lock();
             pos1=1;
             pos2=0;
             pos3=1;
             pos4=0;
             pos5=0;
             pos6=0;
-            POS_MUTEX.unlock();
+            //POS_MUTEX.unlock();
             pc.printf("%i should be 7 \n\r",state);
             lcd.filled_circle(col1, row1 , rmole, fill);// 1,3
 lcd.filled_circle(col1, row2 , rmole, fill);
@@ -342,14 +358,14 @@
 lcd.filled_circle(col3, row1 , rmole, mole);
             break;
             case 8:
-            POS_MUTEX.lock();
+            //POS_MUTEX.lock();
             pos1=0;
             pos2=1;
             pos3=0;
             pos4=1;
             pos5=0;
             pos6=1;
-            POS_MUTEX.unlock();
+            //POS_MUTEX.unlock();
             pc.printf("%i should be 8 \n\r",state);
             
 lcd.filled_circle(col1, row1 , rmole, fill);// 2,4,6
@@ -363,14 +379,14 @@
 lcd.filled_circle(col3, row2 , rmole, mole);
             break;
             case 9:
-            POS_MUTEX.lock();
+            //POS_MUTEX.lock();
             pos1=0;
             pos2=0;
             pos3=1;
             pos4=1;
             pos5=0;
             pos6=1;
-            POS_MUTEX.unlock();
+            //POS_MUTEX.unlock();
             pc.printf("%i should be 9 \n\r",state);
             lcd.filled_circle(col1, row1 , rmole, fill);// 3,4,6
 lcd.filled_circle(col1, row2 , rmole, fill);
@@ -383,14 +399,14 @@
 lcd.filled_circle(col3, row2 , rmole, mole);
             break;
             case 10:
-            POS_MUTEX.lock();
+            //POS_MUTEX.lock();
             pos1=1;
             pos2=0;
             pos3=0;
             pos4=0;
             pos5=0;
             pos6=1;
-            POS_MUTEX.unlock();
+            //POS_MUTEX.unlock();
             pc.printf("%i should be 10 \n\r",state);
             lcd.filled_circle(col1, row1 , rmole, fill);// 1,6
 lcd.filled_circle(col1, row2 , rmole, fill);
@@ -402,14 +418,14 @@
 lcd.filled_circle(col3, row2 , rmole, mole);
             break;
             case 11:
-            POS_MUTEX.lock();
+            //POS_MUTEX.lock();
             pos1=0;
             pos2=1;
             pos3=1;
             pos4=0;
             pos5=1;
             pos6=1;
-            POS_MUTEX.unlock();
+            //POS_MUTEX.unlock();
             pc.printf("%i should be 11 \n\r",state);
             lcd.filled_circle(col1, row1 , rmole, fill);// 2,3,5,6
 lcd.filled_circle(col1, row2 , rmole, fill);
@@ -423,14 +439,14 @@
 lcd.filled_circle(col3, row2 , rmole, mole);
             break;
             case 12:
-            POS_MUTEX.lock();
+            //POS_MUTEX.lock();
             pos1=0;
             pos2=0;
             pos3=1;
             pos4=0;
             pos5=1;
             pos6=0;
-            POS_MUTEX.unlock();
+            //POS_MUTEX.unlock();
             pc.printf("%i should be 12 \n\r",state);
             lcd.filled_circle(col1, row1 , rmole, fill);// 3,5
 lcd.filled_circle(col1, row2 , rmole, fill);
@@ -442,14 +458,14 @@
 lcd.filled_circle(col2, row2 , rmole, mole);
             break;
             case 13:
-            POS_MUTEX.lock();
+            //POS_MUTEX.lock();
             pos1=1;
             pos2=0;
             pos3=0;
             pos4=1;
             pos5=1;
             pos6=0;
-            POS_MUTEX.unlock();
+            //POS_MUTEX.unlock();
             pc.printf("%i should be 13 \n\r",state);
             lcd.filled_circle(col1, row1 , rmole, fill);// 1,4,5
 lcd.filled_circle(col1, row2 , rmole, fill);
@@ -462,14 +478,14 @@
 lcd.filled_circle(col2, row2 , rmole, mole);
             break;
             case 14:
-            POS_MUTEX.lock();
+            //POS_MUTEX.lock();
             pos1=0;
             pos2=1;
             pos3=0;
             pos4=0;
             pos5=1;
             pos6=0;
-            POS_MUTEX.unlock();
+            //POS_MUTEX.unlock();
             pc.printf("%i should be 14 \n\r",state);
             
 lcd.filled_circle(col1, row1 , rmole, fill);// 2,5
@@ -485,7 +501,10 @@
         wait(2);
         counter++;
         }
+        wait(3);
         pc.printf("you scored %i \n\r",score);
+        lcd.text_string("What does...", 1, 1, FONT_7X8, GREEN);
+        lcd.text_string("What does...", 1, 2, FONT_7X8, BLUE);
     }