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:
7:5a8f9a018e1f
Parent:
6:ca03b9c94c88
Child:
8:e6e1e5b3f2a9
--- a/main.cpp	Mon Mar 14 05:43:51 2016 +0000
+++ b/main.cpp	Mon Mar 14 08:12:15 2016 +0000
@@ -73,31 +73,37 @@
     {
         mySpeaker.PlaySong(note,duration);
         score++;
+        pos1 = 0;
     }
         if (value==16&&pos2==1)
     {
         mySpeaker.PlaySong(note,duration);
         score++;
+        pos2 = 0;
     }
         if (value==1&&pos3==1)
             {
         mySpeaker.PlaySong(note,duration);
         score++;
+        pos3 = 0;
     }
         if (value==512&&pos4==1)
     {
         mySpeaker.PlaySong(note,duration);
         score++;
+        pos4 = 0;
     }
         if (value==32&&pos5==1)
     {
         mySpeaker.PlaySong(note,duration);
         score++;
+        pos5 = 0;
     }
         if (value==2&&pos6==1)
     {
         mySpeaker.PlaySong(note,duration);
         score++;
+        pos6 = 0;
     }
     pc.printf("MPR value: %x \r\n", value);
     /*if (value == 1)
@@ -512,35 +518,76 @@
         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, 8, FONT_7X8, BLUE);
+        lcd.cls();
+       /* mkdir("/sd/mydir", 0777);
+        FILE *fp = fopen("/sd/mydir/highscore.txt", "w");
+        pc.printf("Could not open file for write\n");
+        
+        fprintf(fp,"titties");
+        fclose(fp);
+        
+        lcd.printf("The high schore is %s,
         lcd.printf("you scored %D",score);
-        /*FILE *fp = fopen("/sd/mydir/sdtest.txt", "w");
+        FILE *fp = fopen("/sd/mydir/sdtest.txt", "w");
         if(fp == NULL) {
         pc.printf("Could not open file for write\n");
         }
         fprintf(fp, "Hello fun SD Card World!");
-        fclose(fp);*/
-            static const char SampleString[] = "Hello World\n";
-    mkdir("/sd/write_test", 0777);
-    FILE *fp = fopen("/sd/write_test/out.txt", "w");
-    //FILE* fp = fopen("/local/out.txt", "w");
-    if(fp == NULL) 
-    {
-        error("Could not open file for write\n");
+        fclose(fp);*//*
+    char str [80];
+    mkdir("/sd/mydir", 0777);
+    FILE *fp = fopen("/sd/mydir/sdtest.txt", "w");
+    if(fp == NULL) {
+        pc.printf("Could not open file for write\n");
     }
-    fprintf(fp, "Hello from SD Card World!");    
-    fclose(fp); 
-    FILE *fp1 = fopen("/sd/mydir/sdtest.txt", "r"); 
+    fprintf(fp, "%d is the high score score);
+    fclose(fp); FILE *fp1 = fopen("/sd/mydir/sdtest.txt", "r"); 
     if(fp1 == NULL) 
     { 
-    error("Could not open file for read\n"); 
+    pc.printf("Could not open file for read\n"); 
     }
     pc.printf("Opened file for read\n\r");
     fscanf (fp1, "%s", str);
     pc.printf ("I have read:   %s \n",str);
     fclose(fp1);
+ 
+    pc.printf("Goodbye World!\n");*/
+    int please;
+    mkdir("/sd/mydir", 0777);
+    FILE *fp1 = fopen("/sd/mydir/sdtest.txt", "r"); 
+    if(fp1 == NULL) 
+    { 
+    pc.printf("Could not open file for read\n"); 
+    }
+    pc.printf("Opened file for read\n\r");
+    fscanf (fp1, "%s", str);
+    sscanf(str, "%d", &please);
+    pc.printf ("I have read:   %d \n",please);
+    fclose(fp1);
+    FILE *fp = fopen("/sd/mydir/sdtest.txt", "w");
+    if(fp == NULL) {
+        error("Could not open file for write\n");
+    }
+    char buf[10];
+    int a = 5;
+    sprintf(buf, "%d", a);
+    fprintf(fp, "%s",buf);
+    fclose(fp); 
+    FILE *fp2 = fopen("/sd/mydir/sdtest.txt", "r"); 
+    if(fp2 == NULL) 
+    { 
+    error("Could not open file for read\n"); 
+    }
+    pc.printf("Opened file for read\n\r");
+    fscanf (fp2, "%s", str);
+    sscanf(str, "%d", &please);
+    pc.printf ("I have read:   %s \n",str);
+    fclose(fp2);
+ if (please == 5)
+ {
+    pc.printf("we got it\n");
+    }
+    pc.printf("Goodbye World!\n");
     }