f
Dependencies: mbed 4DGL-uLCD-SE MMA8452
hardware.cpp@6:453dc852ac0f, 2022-04-12 (annotated)
- Committer:
- dfrausto3
- Date:
- Tue Apr 12 01:39:20 2022 +0000
- Revision:
- 6:453dc852ac0f
- Parent:
- 5:077b66dfe296
f
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
lballard9 | 0:8e3b9bb1084a | 1 | // This header has all the (extern) declarations of the globals. |
lballard9 | 0:8e3b9bb1084a | 2 | // "extern" means "this is instantiated somewhere, but here's what the name |
lballard9 | 0:8e3b9bb1084a | 3 | // means. |
lballard9 | 0:8e3b9bb1084a | 4 | #include "globals.h" |
lballard9 | 0:8e3b9bb1084a | 5 | |
lballard9 | 0:8e3b9bb1084a | 6 | #include "hardware.h" |
lballard9 | 0:8e3b9bb1084a | 7 | |
lballard9 | 0:8e3b9bb1084a | 8 | // We need to actually instantiate all of the globals (i.e. declare them once |
lballard9 | 0:8e3b9bb1084a | 9 | // without the extern keyword). That's what this file does! |
lballard9 | 0:8e3b9bb1084a | 10 | |
lballard9 | 0:8e3b9bb1084a | 11 | // Hardware initialization: Instantiate all the things! |
lballard9 | 0:8e3b9bb1084a | 12 | uLCD_4DGL uLCD(p9,p10,p11); // LCD Screen (tx, rx, reset) |
lballard9 | 0:8e3b9bb1084a | 13 | //SDFileSystem sd(p5, p6, p7, p8, "sd"); // SD Card(mosi, miso, sck, cs) |
lballard9 | 0:8e3b9bb1084a | 14 | Serial pc(USBTX,USBRX); // USB Console (tx, rx) |
lballard9 | 0:8e3b9bb1084a | 15 | MMA8452 acc(p28, p27, 100000); // Accelerometer (sda, sdc, rate) |
lballard9 | 0:8e3b9bb1084a | 16 | DigitalIn button1(p21); // Pushbuttons (pin) |
lballard9 | 0:8e3b9bb1084a | 17 | DigitalIn button2(p22); |
lballard9 | 0:8e3b9bb1084a | 18 | DigitalIn button3(p23); |
lballard9 | 0:8e3b9bb1084a | 19 | AnalogOut DACout(p18); // Speaker (pin) |
lballard9 | 0:8e3b9bb1084a | 20 | PwmOut speaker(p25); |
lballard9 | 0:8e3b9bb1084a | 21 | wave_player waver(&DACout); |
lballard9 | 0:8e3b9bb1084a | 22 | |
lballard9 | 0:8e3b9bb1084a | 23 | |
lballard9 | 0:8e3b9bb1084a | 24 | // Some hardware also needs to have functions called before it will set up |
lballard9 | 0:8e3b9bb1084a | 25 | // properly. Do that here. |
lballard9 | 0:8e3b9bb1084a | 26 | int hardware_init() |
lballard9 | 0:8e3b9bb1084a | 27 | { |
lwills | 5:077b66dfe296 | 28 | // Crank up the speed |
lwills | 5:077b66dfe296 | 29 | uLCD.baudrate(3000000); |
lwills | 5:077b66dfe296 | 30 | pc.baud(115200); |
lwills | 5:077b66dfe296 | 31 | |
lwills | 5:077b66dfe296 | 32 | //Initialize pushbuttons |
lwills | 5:077b66dfe296 | 33 | button1.mode(PullUp); |
lwills | 5:077b66dfe296 | 34 | button2.mode(PullUp); |
lwills | 5:077b66dfe296 | 35 | button3.mode(PullUp); |
lwills | 5:077b66dfe296 | 36 | |
lwills | 5:077b66dfe296 | 37 | return ERROR_NONE; |
lballard9 | 0:8e3b9bb1084a | 38 | } |
lballard9 | 0:8e3b9bb1084a | 39 | /* |
lballard9 | 0:8e3b9bb1084a | 40 | * This function reads the values of the push buttons and the |
lwills | 5:077b66dfe296 | 41 | * accelerometer. You need to add code to complete its implementation. |
lballard9 | 0:8e3b9bb1084a | 42 | */ |
lballard9 | 0:8e3b9bb1084a | 43 | GameInputs read_inputs() |
lballard9 | 0:8e3b9bb1084a | 44 | { |
lwills | 5:077b66dfe296 | 45 | GameInputs in; |
dfrausto3 | 6:453dc852ac0f | 46 | in.b1 = !button1; |
dfrausto3 | 6:453dc852ac0f | 47 | in.b2 = !button2; |
dfrausto3 | 6:453dc852ac0f | 48 | in.b3 = !button3; |
dfrausto3 | 6:453dc852ac0f | 49 | acc.readXYZGravity(&in.ax, &in.ay, &in.az); |
lwills | 5:077b66dfe296 | 50 | return in; |
lballard9 | 0:8e3b9bb1084a | 51 | } |
lwills | 5:077b66dfe296 | 52 |