Su 200943147

Dependencies:   Gamepad N5110 mbed

Revision:
8:3899d883d329
Parent:
7:31dd8865cc44
Child:
9:6ee4c806f3e9
diff -r 31dd8865cc44 -r 3899d883d329 main.cpp
--- a/main.cpp	Wed May 03 21:52:52 2017 +0000
+++ b/main.cpp	Thu May 04 13:28:46 2017 +0000
@@ -7,52 +7,60 @@
     Direction d;
 };
 
-//N5110 lcd(p7,p8,p9,p10,p11,p13,p21);
+//////////////////Object////////////////////
 N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
 Gamepad pad;
 Engine Engine;
+///////////////Function////////////////////
 void Init();
-void Welcome();
+void WelcometoStart();
 
+///////////////MainLoop/////////////////////
 int main()
 {
     Init();
-    //Welcome();
-    // game loop - read input, update the game state and render the display
+    WelcometoStart();
+
+    int fps = 4;       //4 frames per second
+    wait(1.0f/fps);
+
+    // game loop - read input, update the game state and screen display
     while (1) {
         Engine.ReadInput(pad);
-        Engine.Update(pad);
-        Engine.Update1(lcd);
+        Engine.Update(lcd,pad);
         Engine.Pixel(lcd);
-        lcd.refresh();
-        lcd.clear();
-        wait(0.3);
+        wait(1.0f/fps);
     }
 }
 
 void Init()
 {
-    // need to initialise LCD and Gamepad
+    // initialise the LCD and Gamepad
     lcd.init();
     pad.init();
+    lcd.normalMode();      // normal colour mode
+    lcd.setBrightness(0.5); // put LED backlight on 50%
 
     // initialise the game
     Engine.Init(lcd);
-    lcd.normalMode();      // normal colour mode
-    lcd.setBrightness(0.5); // put LED backlight on 50%
 }
 
-void Welcome() {
-    
-    lcd.printString("   Tetris!    ",0,1);  
-    lcd.printString("  Press Start ",0,4);
+void WelcometoStart()
+{
+    lcd.printString("    Welcome   ",0,2);
+    lcd.printString("    Tetris    ",0,3);
+    lcd.printString("  Press Start ",0,5);
     lcd.refresh();
-     
-    // flashing LEDs until start button is pressed 
+
+    // flashing LEDs until start button is pressed
     while ( pad.check_event(Gamepad::START_PRESSED) == false) {
-        pad.leds_on();
-        wait(0.1);
-        pad.leds_off();
-        wait(0.1);
+        for(int a=0; a<7; a++) {
+            pad.led(a,1);                //led on from left to right
+            wait(0.1);                   //time delay
+        }
+        for(int a=6; a>0; a--) {
+            pad.led(a,0);                //led off from right to left
+            wait(0.1);                   //time delay
+        }
     }
 }
\ No newline at end of file