![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Adventure game written for ECE2035 at the Georgia Institute of Technology
Dependencies: mbed wave_player 4DGL-uLCD-SE MMA8452
hardware.cpp@5:93a4c396c1af, 2019-10-26 (annotated)
- Committer:
- trmontgomery
- Date:
- Sat Oct 26 15:44:26 2019 +0000
- Revision:
- 5:93a4c396c1af
- Parent:
- 4:cdc54191ff07
test
Who changed what in which revision?
User | Revision | Line number | New 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" |
trmontgomery | 4:cdc54191ff07 | 7 | #include "mbed.h" |
trmontgomery | 4:cdc54191ff07 | 8 | |
rconnorlawson | 0:35660d7952f7 | 9 | |
rconnorlawson | 0:35660d7952f7 | 10 | // We need to actually instantiate all of the globals (i.e. declare them once |
rconnorlawson | 0:35660d7952f7 | 11 | // without the extern keyword). That's what this file does! |
rconnorlawson | 0:35660d7952f7 | 12 | |
rconnorlawson | 0:35660d7952f7 | 13 | // Hardware initialization: Instantiate all the things! |
rconnorlawson | 0:35660d7952f7 | 14 | uLCD_4DGL uLCD(p9,p10,p11); // LCD Screen (tx, rx, reset) |
rconnorlawson | 0:35660d7952f7 | 15 | //SDFileSystem sd(p5, p6, p7, p8, "sd"); // SD Card(mosi, miso, sck, cs) |
rconnorlawson | 0:35660d7952f7 | 16 | Serial pc(USBTX,USBRX); // USB Console (tx, rx) |
rconnorlawson | 0:35660d7952f7 | 17 | MMA8452 acc(p28, p27, 100000); // Accelerometer (sda, sdc, rate) |
rconnorlawson | 0:35660d7952f7 | 18 | DigitalIn button1(p21); // Pushbuttons (pin) |
rconnorlawson | 0:35660d7952f7 | 19 | DigitalIn button2(p22); |
rconnorlawson | 0:35660d7952f7 | 20 | DigitalIn button3(p23); |
rconnorlawson | 0:35660d7952f7 | 21 | AnalogOut DACout(p18); // Speaker (pin) |
rconnorlawson | 1:399033d39feb | 22 | PwmOut speaker(p26); |
rconnorlawson | 0:35660d7952f7 | 23 | wave_player waver(&DACout); |
rconnorlawson | 0:35660d7952f7 | 24 | |
rconnorlawson | 0:35660d7952f7 | 25 | // Some hardware also needs to have functions called before it will set up |
rconnorlawson | 0:35660d7952f7 | 26 | // properly. Do that here. |
rconnorlawson | 0:35660d7952f7 | 27 | int hardware_init() |
rconnorlawson | 0:35660d7952f7 | 28 | { |
rconnorlawson | 0:35660d7952f7 | 29 | // Crank up the speed |
rconnorlawson | 0:35660d7952f7 | 30 | uLCD.baudrate(3000000); |
rconnorlawson | 0:35660d7952f7 | 31 | pc.baud(115200); |
rconnorlawson | 0:35660d7952f7 | 32 | |
rconnorlawson | 0:35660d7952f7 | 33 | //Initialize pushbuttons |
rconnorlawson | 0:35660d7952f7 | 34 | button1.mode(PullUp); |
rconnorlawson | 0:35660d7952f7 | 35 | button2.mode(PullUp); |
rconnorlawson | 0:35660d7952f7 | 36 | button3.mode(PullUp); |
rconnorlawson | 0:35660d7952f7 | 37 | |
rconnorlawson | 0:35660d7952f7 | 38 | return ERROR_NONE; |
rconnorlawson | 0:35660d7952f7 | 39 | } |
rconnorlawson | 0:35660d7952f7 | 40 | |
trmontgomery | 4:cdc54191ff07 | 41 | int butt1; |
trmontgomery | 4:cdc54191ff07 | 42 | |
trmontgomery | 4:cdc54191ff07 | 43 | void debounce(){ |
trmontgomery | 4:cdc54191ff07 | 44 | int _counter = 0; |
trmontgomery | 4:cdc54191ff07 | 45 | int _samples = 10; |
trmontgomery | 4:cdc54191ff07 | 46 | int _shadow = 0; |
trmontgomery | 4:cdc54191ff07 | 47 | |
trmontgomery | 4:cdc54191ff07 | 48 | if (!button1) { |
trmontgomery | 4:cdc54191ff07 | 49 | if (_counter < _samples) _counter++; |
trmontgomery | 4:cdc54191ff07 | 50 | if (_counter == _samples) _shadow = 1; |
trmontgomery | 4:cdc54191ff07 | 51 | } |
trmontgomery | 4:cdc54191ff07 | 52 | else { |
trmontgomery | 4:cdc54191ff07 | 53 | if (_counter > 0) _counter--; |
trmontgomery | 4:cdc54191ff07 | 54 | if (_counter == 0) _shadow = 0; |
trmontgomery | 4:cdc54191ff07 | 55 | } |
trmontgomery | 4:cdc54191ff07 | 56 | butt1 = _shadow; |
trmontgomery | 4:cdc54191ff07 | 57 | } |
trmontgomery | 4:cdc54191ff07 | 58 | |
rconnorlawson | 0:35660d7952f7 | 59 | GameInputs read_inputs() |
rconnorlawson | 0:35660d7952f7 | 60 | { |
trmontgomery | 4:cdc54191ff07 | 61 | Ticker ticker; |
trmontgomery | 4:cdc54191ff07 | 62 | //ticker.attach(&debounce, 1000); |
rconnorlawson | 0:35660d7952f7 | 63 | GameInputs in; |
trmontgomery | 2:0876296d9473 | 64 | acc.readXGravity(&in.ax); |
trmontgomery | 2:0876296d9473 | 65 | acc.readYGravity(&in.ay); |
trmontgomery | 2:0876296d9473 | 66 | acc.readZGravity(&in.az); |
trmontgomery | 4:cdc54191ff07 | 67 | //uLCD.locate(1,1); |
trmontgomery | 4:cdc54191ff07 | 68 | //uLCD.printf("%f\n", butt1); |
trmontgomery | 4:cdc54191ff07 | 69 | |
trmontgomery | 4:cdc54191ff07 | 70 | in.b1 = button1;//butt1; |
trmontgomery | 2:0876296d9473 | 71 | in.b2 = button2; |
trmontgomery | 2:0876296d9473 | 72 | in.b3 = button3; |
rconnorlawson | 0:35660d7952f7 | 73 | return in; |
rconnorlawson | 0:35660d7952f7 | 74 | } |