Game For ECE 2035

Dependencies:   mbed wave_player 4DGL-uLCD-SE MMA8452

Committer:
nasiromar
Date:
Fri Dec 03 19:12:50 2021 +0000
Revision:
18:760dd68e939e
Parent:
14:7225da81314a
New Update;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rconnorlawson 0:35660d7952f7 1 // This header has all the (extern) declarations of the globals.
rconnorlawson 0:35660d7952f7 2 // "extern" means "this is instantiated somewhere, but here's what the name
rconnorlawson 0:35660d7952f7 3 // means.
rconnorlawson 0:35660d7952f7 4 #include "globals.h"
rconnorlawson 0:35660d7952f7 5
rconnorlawson 0:35660d7952f7 6 #include "hardware.h"
rconnorlawson 0:35660d7952f7 7
rconnorlawson 0:35660d7952f7 8 // We need to actually instantiate all of the globals (i.e. declare them once
rconnorlawson 0:35660d7952f7 9 // without the extern keyword). That's what this file does!
rconnorlawson 0:35660d7952f7 10
rconnorlawson 0:35660d7952f7 11 // Hardware initialization: Instantiate all the things!
rconnorlawson 0:35660d7952f7 12 uLCD_4DGL uLCD(p9,p10,p11); // LCD Screen (tx, rx, reset)
nasiromar 9:cbb9cfb1f6c5 13 SDFileSystem sd(p5, p6, p7, p8, "sd"); // SD Card(mosi, miso, sck, cs)
rconnorlawson 0:35660d7952f7 14 Serial pc(USBTX,USBRX); // USB Console (tx, rx)
rconnorlawson 0:35660d7952f7 15 MMA8452 acc(p28, p27, 100000); // Accelerometer (sda, sdc, rate)
rconnorlawson 0:35660d7952f7 16 DigitalIn button1(p21); // Pushbuttons (pin)
rconnorlawson 0:35660d7952f7 17 DigitalIn button2(p22);
rconnorlawson 0:35660d7952f7 18 DigitalIn button3(p23);
nasiromar 6:c9695079521d 19 DigitalIn button4(p24);
rconnorlawson 0:35660d7952f7 20 AnalogOut DACout(p18); // Speaker (pin)
rconnorlawson 1:399033d39feb 21 PwmOut speaker(p26);
rconnorlawson 0:35660d7952f7 22 wave_player waver(&DACout);
rconnorlawson 0:35660d7952f7 23
rconnorlawson 0:35660d7952f7 24 // Some hardware also needs to have functions called before it will set up
rconnorlawson 0:35660d7952f7 25 // properly. Do that here.
rconnorlawson 0:35660d7952f7 26 int hardware_init()
rconnorlawson 0:35660d7952f7 27 {
rconnorlawson 0:35660d7952f7 28 // Crank up the speed
rconnorlawson 0:35660d7952f7 29 uLCD.baudrate(3000000);
rconnorlawson 0:35660d7952f7 30 pc.baud(115200);
rconnorlawson 0:35660d7952f7 31
rconnorlawson 0:35660d7952f7 32 //Initialize pushbuttons
rconnorlawson 0:35660d7952f7 33 button1.mode(PullUp);
rconnorlawson 0:35660d7952f7 34 button2.mode(PullUp);
rconnorlawson 0:35660d7952f7 35 button3.mode(PullUp);
nasiromar 14:7225da81314a 36 //button4.mode(PullUp);
nasiromar 6:c9695079521d 37 acc.activate();
rconnorlawson 0:35660d7952f7 38
rconnorlawson 0:35660d7952f7 39 return ERROR_NONE;
rconnorlawson 0:35660d7952f7 40 }
rconnorlawson 0:35660d7952f7 41
rconnorlawson 0:35660d7952f7 42 GameInputs read_inputs()
rconnorlawson 0:35660d7952f7 43 {
rconnorlawson 0:35660d7952f7 44 GameInputs in;
nasiromar 6:c9695079521d 45
nasiromar 6:c9695079521d 46 //Accelerometer readings
nasiromar 6:c9695079521d 47 acc.readXGravity(&in.ax);
nasiromar 6:c9695079521d 48 acc.readYGravity(&in.ay);
nasiromar 6:c9695079521d 49 acc.readZGravity(&in.az);
nasiromar 6:c9695079521d 50
nasiromar 6:c9695079521d 51
nasiromar 6:c9695079521d 52 //button readings
nasiromar 6:c9695079521d 53 in.b1 = button1.read();
nasiromar 6:c9695079521d 54 in.b2 = button2.read();
nasiromar 6:c9695079521d 55 in.b3 = button3.read();
nasiromar 6:c9695079521d 56 in.b4 = button3.read();
nasiromar 6:c9695079521d 57
rconnorlawson 0:35660d7952f7 58 return in;
rconnorlawson 0:35660d7952f7 59 }