f

Dependencies:   mbed 4DGL-uLCD-SE MMA8452

Files at this revision

API Documentation at this revision

Comitter:
lwills
Date:
Mon Mar 14 23:38:03 2022 +0000
Parent:
4:0c0940591fb1
Child:
6:453dc852ac0f
Commit message:
added more documentation

Changed in this revision

globals.h Show annotated file Show diff for this revision Revisions of this file
graphics.h Show annotated file Show diff for this revision Revisions of this file
hardware.cpp Show annotated file Show diff for this revision Revisions of this file
keyboard.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/globals.h	Fri Mar 11 14:11:58 2022 +0000
+++ b/globals.h	Mon Mar 14 23:38:03 2022 +0000
@@ -1,7 +1,7 @@
 //=================================================================
 // The header file for general settings for the project
 //
-// Copyright 2020 Georgia Tech.  All rights reserved.
+// Copyright 2022 Georgia Tech.  All rights reserved.
 // The materials provided by the instructor in this course are for
 // the use of the students currently enrolled in the course.
 // Copyrighted course materials may not be further disseminated.
@@ -16,11 +16,22 @@
 #include "MMA8452.h"
 #include <math.h>
 
-// === [global object] ===
-extern uLCD_4DGL uLCD;
+/*
+This file holds all the global variables that are accessable from all the 
+different files in this project. You see below most of it looks like hardware.
+That's because it is hardware! The uLCD object is how you interact with the LCD
+screen. The sd variable is how you interact with the sd card and so on for all
+the other variables.
+*/
+extern uLCD_4DGL uLCD;      // LCD Screen
 extern Serial pc;           // USB Console output
+extern MMA8452 acc;         // Accelerometer
+extern DigitalIn button1;   // Pushbuttons
+extern DigitalIn button2;
+extern DigitalIn button3;
+extern AnalogOut DACout;    // Speaker
+extern PwmOut speaker;
 extern wave_player waver;
-extern PwmOut speaker;
 
 // === [global settings] ===
 // === [define the macro of error handle function] ===
@@ -38,6 +49,6 @@
 
 #define ERROR_DLL_INSERT_HEAD             -14 // inserting into doubly linked list at head failed
 #define ERROR_DLL_DELETE                  -15 // deleting node from doubly linked list failed
-// other anti-fruit error code ...
+// add other error codes ...
 
 #endif //GLOBAL_H
--- a/graphics.h	Fri Mar 11 14:11:58 2022 +0000
+++ b/graphics.h	Mon Mar 14 23:38:03 2022 +0000
@@ -4,8 +4,7 @@
  
 
 // The bottom of the screen => y=127
-// Gut the landscape grow up from the bottom of the screen. It is awkward.
-// Thus, we use a macro to reverse the coordinate for convenience.
+// A macro to reverse the coordinate for convenience (optional).
 #define REVERSE_Y(x) (SIZE_Y-(x))
 
 /**
--- a/hardware.cpp	Fri Mar 11 14:11:58 2022 +0000
+++ b/hardware.cpp	Mon Mar 14 23:38:03 2022 +0000
@@ -25,13 +25,24 @@
 // properly. Do that here.
 int hardware_init()
 {    
-
+    // Crank up the speed
+    uLCD.baudrate(3000000);
+    pc.baud(115200);
+        
+    //Initialize pushbuttons
+    button1.mode(PullUp); 
+    button2.mode(PullUp);
+    button3.mode(PullUp);
+    
+    return ERROR_NONE;
 }
 /*
 * This function reads the values of the push buttons and the 
-* accelerometer
+* accelerometer.  You need to add code to complete its implementation.
 */
 GameInputs read_inputs() 
 {
-    
+    GameInputs in;
+    return in;
 }
+
--- a/keyboard.h	Fri Mar 11 14:11:58 2022 +0000
+++ b/keyboard.h	Mon Mar 14 23:38:03 2022 +0000
@@ -18,9 +18,13 @@
 /*
 * This function should intialize the keyboard and 
 * select the goal word. To pick goal word, select a word 
-* randonly from the dictionary you create in dictionary.h.
+* randomly from the dictionary you create in dictionary.h 
+* (hint: the function rand() can be used to generate a random
+* number >=0).
 * To create the keyboard, initialize a DLL with all the nodes
-* being the letters of the alphabet.
+* being the letters of the alphabet. Display the visible part
+* of the keyboard at the start of the game (e.g., for baseline: 
+* display the first letter of the alphabet).
 */
 void init_keyboard();
 
--- a/main.cpp	Fri Mar 11 14:11:58 2022 +0000
+++ b/main.cpp	Mon Mar 14 23:38:03 2022 +0000
@@ -24,7 +24,7 @@
 DigitalOut myled3(LED3);
 DigitalOut myled4(LED4);
 
-void set_random_seed(Timer);
+void set_random_seed();
 
 /*
 * This function handles the main logic of the game. You should
@@ -45,14 +45,24 @@
     Timer t;
     int dt; // delta time
     
+/* Put code here to initialize the game state:
+   1) you will need to use a psuedo random number generator such as
+     rand() to randomly select a goal word from the dictionary.
+     The random function needs to be seeded before you call rand(),
+     otherwise, rand() will always generate the same series of numbers.
+     Call the function set_random_seed -- you need to complete its
+     definition below.*/
+    set_random_seed();
 /*
-Put your code for main menu here, seed random function here as well
+   2) call init_keyboard() and show start screen
+   
+   3) initialize any other game state that you add.
 */
-
-// initialize the game state, print something to the screen and wait for an input.
-// do that before entering this game loop
-
-while(1){
+    
+    
+/* Insert code into this game loop to complete its implementation:
+*/
+    while(1){
         t.start(); //start a timer
         draw_lower_status(); //draw the lower status bar
         inputs = read_inputs(); //read the inputs of the game
@@ -72,24 +82,28 @@
 
 
 
-/*
-* This function sets the random seed for the game. 
-* It also initializes the keyboard. You may choose to
-* put the start screen in here as well. This should be
-* called in the main function above.
+/* This should be called in the main function above.
+*
+* This function sets the random seed for the game using srand(seed).
+* One incomplete way to do this is given below: start a Timer and sample it
+* to get a seed. The problem is that the same exact time will be read
+* every time you reset the mbed.  You need to add code to introduce
+* variability into when the timer is stopped.  An easy way to do this
+* is to get the user to press a push button to stop the timer at a random
+* time.  You can print a prompt to the screen to ask the user to push
+* any button to start, then run an infinite while loop that waits for a push 
+* button press to break. The Timer is then stopped and read and elapsed time
+* used as the seed. (This requires using read_inputs() into a GameInputs variable.)
 */
-void set_random_seed(Timer t) {
-    
+void set_random_seed() {
+    Timer t;
+    t.start(); // start the timer
+    wait_ms(200);
+    // add code here
+    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
     
-// set up a GameInputs variable
-//run t.start(); to start the timer
-// create a while loop that waits for player input to break
-//run t.stop(); to end the timer
-//int seed = t.read_ms(); to read the number of milliseconds elapsed between the start and stop
-//call srand(seed);
-//run init_keyboard();
-
-
-
+    uLCD.printf("seed: %d\n", seed); // TEMP: delete this
 }
 // ===User implementations end===