Konlatee Sittichaivijit / Mbed 2 deprecated PacManII

Dependencies:   N5110 PowerControl mbed

Revision:
25:55331fbafc67
Parent:
24:410cba08be6b
Child:
26:4cfeb2c29326
--- a/main.cpp	Fri May 01 12:02:46 2015 +0000
+++ b/main.cpp	Tue May 05 17:39:08 2015 +0000
@@ -18,8 +18,13 @@
 LocalFileSystem local("local"); // define local file system
  char buffer1[14];
  char buffer[14];
+PwmOut PWM1(p23); //Yellow pin of RGB
+PwmOut PWM2(p22);//Green pin of RGB
+PwmOut PWM3(p24);//Red pin of RGB
+
+
 // Function Prototypes
-void pressWasted();
+void pressStart();
 
 void  pause();
 void  winningcondition();
@@ -146,6 +151,7 @@
     while (buttonflag) {
         lcd.clear();
         lcd.printString("Pause", 25,21);
+        lcd.setBrightness(bright);
         while (timerflag) {// Device goes into sleep and lcd is powered down after 15 seconds in pause menu
             timer.detach();
             lcd.turnOff();
@@ -510,10 +516,10 @@
     }
 }
 
-void pressWasted()  // ISR to swap direction of joystick
+void pressStart()  // ISR to Start game
 {
 
-    buttonflag1=!buttonflag1;
+    buttonflag1++;
 }
 
 void WastedMode()
@@ -533,10 +539,49 @@
     }
 }
 
+
+
+
+void startscreen(){
+     lcd.printString("Welcome to",15,1);
+    lcd.printString("Pacman",20,2);
+    lcd.printString("Press Start",6,3);
+    button.rise(&pressStart); // event generated on rising edge
+    PWM1.period_us(25);// Set time period
+    if(buttonflag1==1){
+        lcd.clear(); 
+        lcd.printString("Ready",21,2);
+        PWM1 = 0.0;//Duty Cycle of Green pin
+        PWM2 = 0.0;//Duty cycle of Yellow pin
+        PWM3 = 0.5;//Duty Cycle of Red pin
+        wait(1.0) ;
+        lcd.clear();
+        lcd.printString("Set",23,2);
+        PWM1 = 0.5;//Duty Cycle of Yellow pin
+        PWM2 = 0.0;//Duty cycle of Grren pin
+        PWM3 = 0.0;//Duty Cycle of Red pin
+        wait(1.0);
+        lcd.clear();
+        lcd.printString("Go!",23,2);
+        PWM1 = 0.0;//Duty Cycle of Yellow pin
+        PWM2 = 0.5;//Duty cycle of Green pin
+        PWM3 = 0.0;//Duty Cycle of Red pin
+        wait(1.0);
+        lcd.clear();
+        drawMap();  
+        buttonflag1++;
+        
+    }
+       if(buttonflag1==0) {
+           startscreen();
+            }
+
+}
+
 void WastedCheck()
 {
-    button.rise(&pressWasted); // event generated on rising edge
-    if(buttonflag1) {
+    
+    if(w<=8) {
         WastedMode();
         drawPacman2();
     } else {
@@ -756,8 +801,7 @@
             score.attach(&scoreexpired,1.0);
             //tune();
             while(win==false&& lose==false) {
-
-
+                startscreen();
                 lcd.setBrightness(bright);
                 lcd.clear();
                 pause();
@@ -794,19 +838,13 @@
                 compareScore(); 
                 wait(5.0); 
                 lcd.clear();
-                creditscreen();
-                  
-                  
-                  
-                  
-                  
-              
+                creditscreen();   
 
             }
             if (lose==true) {
                 lcd.setBrightness(bright);
                 lcd.clear();
-                lcd.printString("Game Over", 10,10);
+                lcd.printString("Game Over",10,3);
                 tune();
                 lcd.clear();
                 creditscreen();