f

Dependencies:   mbed 4DGL-uLCD-SE MMA8452

Committer:
lwills
Date:
Mon Mar 14 23:38:03 2022 +0000
Revision:
5:077b66dfe296
Parent:
4:0c0940591fb1
Child:
6:453dc852ac0f
added more documentation

Who changed what in which revision?

UserRevisionLine numberNew contents of line
lballard9 0:8e3b9bb1084a 1 //=================================================================
lballard9 0:8e3b9bb1084a 2 // The main program file.
lballard9 0:8e3b9bb1084a 3 //
lballard9 0:8e3b9bb1084a 4 // Copyright 2022 Georgia Tech. All rights reserved.
lballard9 0:8e3b9bb1084a 5 // The materials provided by the instructor in this course are for
lballard9 0:8e3b9bb1084a 6 // the use of the students currently enrolled in the course.
lballard9 0:8e3b9bb1084a 7 // Copyrighted course materials may not be further disseminated.
lballard9 0:8e3b9bb1084a 8 // This file must not be made publicly available anywhere.
lballard9 0:8e3b9bb1084a 9 //==================================================================
lballard9 0:8e3b9bb1084a 10
lballard9 0:8e3b9bb1084a 11 // External libs
lballard9 0:8e3b9bb1084a 12 #include <stdlib.h>
lballard9 0:8e3b9bb1084a 13
lballard9 0:8e3b9bb1084a 14 // Project includes
lballard9 0:8e3b9bb1084a 15 #include "globals.h"
lballard9 0:8e3b9bb1084a 16 #include "hardware.h"
lballard9 0:8e3b9bb1084a 17 #include "graphics.h"
lballard9 0:8e3b9bb1084a 18 #include "keyboard.h"
lballard9 1:d57364f0349f 19
lballard9 1:d57364f0349f 20
lballard9 2:ca5910acbade 21 //some LED's to use for debugging.
lballard9 1:d57364f0349f 22 DigitalOut myled1(LED1);
lballard9 1:d57364f0349f 23 DigitalOut myled2(LED2);
lballard9 1:d57364f0349f 24 DigitalOut myled3(LED3);
lballard9 1:d57364f0349f 25 DigitalOut myled4(LED4);
lballard9 0:8e3b9bb1084a 26
lwills 5:077b66dfe296 27 void set_random_seed();
lballard9 0:8e3b9bb1084a 28
lballard9 0:8e3b9bb1084a 29 /*
lballard9 0:8e3b9bb1084a 30 * This function handles the main logic of the game. You should
lballard9 0:8e3b9bb1084a 31 * initialize the hardware in this function, make calls to
lballard9 0:8e3b9bb1084a 32 * functions that update the keyboard and your guess of
lballard9 0:8e3b9bb1084a 33 * the word.
lballard9 0:8e3b9bb1084a 34 */
lballard9 0:8e3b9bb1084a 35 int main()
lballard9 0:8e3b9bb1084a 36 {
lballard9 1:d57364f0349f 37
lballard9 1:d57364f0349f 38 GameInputs inputs;
lballard9 1:d57364f0349f 39 // First things first: initialize hardware
lballard9 1:d57364f0349f 40 ASSERT_P(hardware_init() == ERROR_NONE, "Hardware init failed!");
lballard9 1:d57364f0349f 41 pc.printf("Program Starting\n");
lballard9 1:d57364f0349f 42 //led1 hardware initialization
lballard9 1:d57364f0349f 43
lballard9 1:d57364f0349f 44 myled1=1;
lballard9 1:d57364f0349f 45 Timer t;
lballard9 1:d57364f0349f 46 int dt; // delta time
lballard9 1:d57364f0349f 47
lwills 5:077b66dfe296 48 /* Put code here to initialize the game state:
lwills 5:077b66dfe296 49 1) you will need to use a psuedo random number generator such as
lwills 5:077b66dfe296 50 rand() to randomly select a goal word from the dictionary.
lwills 5:077b66dfe296 51 The random function needs to be seeded before you call rand(),
lwills 5:077b66dfe296 52 otherwise, rand() will always generate the same series of numbers.
lwills 5:077b66dfe296 53 Call the function set_random_seed -- you need to complete its
lwills 5:077b66dfe296 54 definition below.*/
lwills 5:077b66dfe296 55 set_random_seed();
lballard9 1:d57364f0349f 56 /*
lwills 5:077b66dfe296 57 2) call init_keyboard() and show start screen
lwills 5:077b66dfe296 58
lwills 5:077b66dfe296 59 3) initialize any other game state that you add.
lballard9 1:d57364f0349f 60 */
lwills 5:077b66dfe296 61
lwills 5:077b66dfe296 62
lwills 5:077b66dfe296 63 /* Insert code into this game loop to complete its implementation:
lwills 5:077b66dfe296 64 */
lwills 5:077b66dfe296 65 while(1){
lballard9 1:d57364f0349f 66 t.start(); //start a timer
lballard9 1:d57364f0349f 67 draw_lower_status(); //draw the lower status bar
lballard9 1:d57364f0349f 68 inputs = read_inputs(); //read the inputs of the game
lballard9 1:d57364f0349f 69
lballard9 1:d57364f0349f 70
lballard9 1:d57364f0349f 71 /*
lballard9 1:d57364f0349f 72 your code here, make decisions based on those inputs, update the keyboard
lballard9 1:d57364f0349f 73 make selections, update words etc.
lballard9 1:d57364f0349f 74 */
lballard9 1:d57364f0349f 75
lballard9 1:d57364f0349f 76 t.stop();
lballard9 1:d57364f0349f 77 dt = t.read_ms();
lballard9 4:0c0940591fb1 78 if (dt < 100) wait_ms(100 - dt);
lballard9 1:d57364f0349f 79
lballard9 1:d57364f0349f 80 }
lballard9 0:8e3b9bb1084a 81 }
lballard9 0:8e3b9bb1084a 82
lballard9 1:d57364f0349f 83
lballard9 0:8e3b9bb1084a 84
lwills 5:077b66dfe296 85 /* This should be called in the main function above.
lwills 5:077b66dfe296 86 *
lwills 5:077b66dfe296 87 * This function sets the random seed for the game using srand(seed).
lwills 5:077b66dfe296 88 * One incomplete way to do this is given below: start a Timer and sample it
lwills 5:077b66dfe296 89 * to get a seed. The problem is that the same exact time will be read
lwills 5:077b66dfe296 90 * every time you reset the mbed. You need to add code to introduce
lwills 5:077b66dfe296 91 * variability into when the timer is stopped. An easy way to do this
lwills 5:077b66dfe296 92 * is to get the user to press a push button to stop the timer at a random
lwills 5:077b66dfe296 93 * time. You can print a prompt to the screen to ask the user to push
lwills 5:077b66dfe296 94 * any button to start, then run an infinite while loop that waits for a push
lwills 5:077b66dfe296 95 * button press to break. The Timer is then stopped and read and elapsed time
lwills 5:077b66dfe296 96 * used as the seed. (This requires using read_inputs() into a GameInputs variable.)
lballard9 0:8e3b9bb1084a 97 */
lwills 5:077b66dfe296 98 void set_random_seed() {
lwills 5:077b66dfe296 99 Timer t;
lwills 5:077b66dfe296 100 t.start(); // start the timer
lwills 5:077b66dfe296 101 wait_ms(200);
lwills 5:077b66dfe296 102 // add code here
lwills 5:077b66dfe296 103 t.stop(); // end the timer
lwills 5:077b66dfe296 104 int seed = t.read_ms(); //read the number of milliseconds elapsed between the start and stop
lwills 5:077b66dfe296 105 srand(seed); // use elapsed time as the seed
lballard9 3:ebf55ea6f18b 106
lwills 5:077b66dfe296 107 uLCD.printf("seed: %d\n", seed); // TEMP: delete this
lballard9 0:8e3b9bb1084a 108 }
lballard9 0:8e3b9bb1084a 109 // ===User implementations end===