project for 2035
Dependencies: mbed wave_player 4DGL-uLCD-SE MMA8452
hardware.cpp@22:33f1a0dff46c, 2020-11-25 (annotated)
- Committer:
- kblake9
- Date:
- Wed Nov 25 04:48:22 2020 +0000
- Revision:
- 22:33f1a0dff46c
- Parent:
- 15:770c2720d0cc
final
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
DCchico | 2:4947d6a82971 | 1 | // Copyright 2020 Georgia Tech. All rights reserved. |
DCchico | 2:4947d6a82971 | 2 | // The materials provided by the instructor in this course are for |
DCchico | 2:4947d6a82971 | 3 | // the use of the students currently enrolled in the course. |
DCchico | 2:4947d6a82971 | 4 | // Copyrighted course materials may not be further disseminated. |
DCchico | 2:4947d6a82971 | 5 | // This file must not be made publicly available anywhere. |
DCchico | 2:4947d6a82971 | 6 | |
DCchico | 1:10330bce85cb | 7 | // This header has all the (extern) declarations of the globals. |
DCchico | 1:10330bce85cb | 8 | // "extern" means "this is instantiated somewhere, but here's what the name |
DCchico | 1:10330bce85cb | 9 | // means. |
DCchico | 1:10330bce85cb | 10 | #include "globals.h" |
DCchico | 1:10330bce85cb | 11 | |
DCchico | 1:10330bce85cb | 12 | #include "hardware.h" |
DCchico | 1:10330bce85cb | 13 | |
DCchico | 1:10330bce85cb | 14 | // We need to actually instantiate all of the globals (i.e. declare them once |
DCchico | 1:10330bce85cb | 15 | // without the extern keyword). That's what this file does! |
DCchico | 1:10330bce85cb | 16 | |
DCchico | 1:10330bce85cb | 17 | // Hardware initialization: Instantiate all the things! |
DCchico | 1:10330bce85cb | 18 | uLCD_4DGL uLCD(p9,p10,p11); // LCD Screen (tx, rx, reset) |
kblake9 | 5:cd2bdbfedd21 | 19 | //SDFileSystem sd(p5, p6, p7, p8, "sd"); // SD Card(mosi, miso, sck, cs) |
DCchico | 1:10330bce85cb | 20 | Serial pc(USBTX,USBRX); // USB Console (tx, rx) |
kblake9 | 12:5141f85e0be6 | 21 | MMA8452 acc(p28, p27, 100000); // Accelerometer (sda, sdc, rate) |
DCchico | 1:10330bce85cb | 22 | DigitalIn button1(p21); // Pushbuttons (pin) |
DCchico | 1:10330bce85cb | 23 | DigitalIn button2(p22); |
DCchico | 1:10330bce85cb | 24 | DigitalIn button3(p23); |
DCchico | 1:10330bce85cb | 25 | AnalogOut DACout(p18); // Speaker (pin) |
DCchico | 1:10330bce85cb | 26 | PwmOut speaker(p26); |
DCchico | 1:10330bce85cb | 27 | wave_player waver(&DACout); |
DCchico | 1:10330bce85cb | 28 | |
DCchico | 1:10330bce85cb | 29 | |
DCchico | 1:10330bce85cb | 30 | // Some hardware also needs to have functions called before it will set up |
DCchico | 1:10330bce85cb | 31 | // properly. Do that here. |
DCchico | 1:10330bce85cb | 32 | int hardware_init() |
DCchico | 1:10330bce85cb | 33 | { |
kblake9 | 12:5141f85e0be6 | 34 | // Crank up the speed and init LCD |
DCchico | 1:10330bce85cb | 35 | uLCD.baudrate(3000000); |
kblake9 | 12:5141f85e0be6 | 36 | uLCD.background_color(BLACK); |
kblake9 | 12:5141f85e0be6 | 37 | uLCD.cls(); |
DCchico | 1:10330bce85cb | 38 | pc.baud(115200); |
DCchico | 1:10330bce85cb | 39 | |
DCchico | 1:10330bce85cb | 40 | //Initialize pushbuttons |
DCchico | 1:10330bce85cb | 41 | button1.mode(PullUp); |
DCchico | 1:10330bce85cb | 42 | button2.mode(PullUp); |
DCchico | 1:10330bce85cb | 43 | button3.mode(PullUp); |
DCchico | 1:10330bce85cb | 44 | |
kblake9 | 12:5141f85e0be6 | 45 | //Initialize accelerometer |
kblake9 | 12:5141f85e0be6 | 46 | acc.activate(); |
kblake9 | 12:5141f85e0be6 | 47 | |
DCchico | 1:10330bce85cb | 48 | return ERROR_NONE; |
DCchico | 1:10330bce85cb | 49 | } |
DCchico | 1:10330bce85cb | 50 | |
DCchico | 2:4947d6a82971 | 51 | // Implement this function. |
DCchico | 2:4947d6a82971 | 52 | // HINT: lookup your accelerometer under mbed site > Hardware> Components |
DCchico | 2:4947d6a82971 | 53 | // and look at demo code |
DCchico | 1:10330bce85cb | 54 | GameInputs read_inputs() |
DCchico | 1:10330bce85cb | 55 | { |
DCchico | 1:10330bce85cb | 56 | GameInputs in; |
kblake9 | 13:bd2e05cebd5d | 57 | in.b1 = button1.read(); |
kblake9 | 13:bd2e05cebd5d | 58 | in.b2 = button2.read(); |
kblake9 | 13:bd2e05cebd5d | 59 | in.b3 = button3.read(); |
kblake9 | 22:33f1a0dff46c | 60 | acc.readXYZGravity(&in.ax,&in.ay,&in.az); |
DCchico | 1:10330bce85cb | 61 | return in; |
DCchico | 1:10330bce85cb | 62 | } |