f

Dependencies:   mbed 4DGL-uLCD-SE MMA8452

Revision:
6:453dc852ac0f
Parent:
5:077b66dfe296
--- a/main.cpp	Mon Mar 14 23:38:03 2022 +0000
+++ b/main.cpp	Tue Apr 12 01:39:20 2022 +0000
@@ -26,6 +26,7 @@
 
 void set_random_seed();
 
+
 /*
 * This function handles the main logic of the game. You should
 * initialize the hardware in this function, make calls to 
@@ -33,9 +34,7 @@
 * the word. 
 */
 int main()
-{
-    
-    GameInputs inputs; 
+{ 
     // First things first: initialize hardware
     ASSERT_P(hardware_init() == ERROR_NONE, "Hardware init failed!");
     pc.printf("Program Starting\n");
@@ -53,11 +52,11 @@
      Call the function set_random_seed -- you need to complete its
      definition below.*/
     set_random_seed();
-/*
-   2) call init_keyboard() and show start screen
+   //2) call init_keyboard() and show start screen
+    init_keyboard();
    
-   3) initialize any other game state that you add.
-*/
+   //3) initialize any other game state that you add.
+
     
     
 /* Insert code into this game loop to complete its implementation:
@@ -65,8 +64,19 @@
     while(1){
         t.start(); //start a timer
         draw_lower_status(); //draw the lower status bar
+        draw_sprite();
+        GameInputs inputs;
         inputs = read_inputs(); //read the inputs of the game
         
+        if (inputs.ax > .5 && !inputs.b1 && !inputs.b2 && !inputs.b3) {
+            moveleft();
+        } else if (inputs.ax < -.5 && !inputs.b1 && !inputs.b2 && !inputs.b3) {
+            moveright();
+        } else if (inputs.b1) {
+            select_letter();
+        } else if (inputs.b2) {
+            remove_letter();        
+        }
         
         /*
         your code here, make decisions based on those inputs, update the keyboard
@@ -75,7 +85,7 @@
         
         t.stop();
         dt = t.read_ms();
-        if (dt < 100) wait_ms(100 - dt);
+        if (dt < 500) wait_ms(500 - dt);
         
         }
 }
@@ -97,13 +107,28 @@
 */
 void set_random_seed() {
     Timer t;
+    int start = 1;
+    GameInputs startButton;
     t.start(); // start the timer
-    wait_ms(200);
-    // add code here
+    
+    uLCD.locate(1, 3);
+    uLCD.printf("Welcome to MBEDL");
+    uLCD.printf("\n Press any Button");
+    uLCD.locate(4, 5);
+    uLCD.printf("To Start");
+    
+    while (start) {
+        draw_sprite();
+        startButton = read_inputs();
+        if (startButton.b1 || startButton.b2 || startButton.b3) {
+            start = 0;
+        }
+        wait_ms(200);
+    }
+    
     t.stop();  //  end the timer
     int seed = t.read_ms(); //read the number of milliseconds elapsed between the start and stop
     srand(seed); // use elapsed time as the seed
-    
-    uLCD.printf("seed: %d\n", seed); // TEMP: delete this
+    uLCD.cls();
 }
 // ===User implementations end===