Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed wave_player 4DGL-uLCD-SE MMA8452
hardware.cpp@5:2fb023cdc666, 2019-11-24 (annotated)
- Committer:
- trich9
- Date:
- Sun Nov 24 03:22:35 2019 +0000
- Revision:
- 5:2fb023cdc666
- Parent:
- 4:2297a714936f
finished V1
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" |
| 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) |
| rconnorlawson | 0:35660d7952f7 | 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); |
| rconnorlawson | 0:35660d7952f7 | 19 | AnalogOut DACout(p18); // Speaker (pin) |
| trich9 | 5:2fb023cdc666 | 20 | PwmOut speaker(p26); //MYCODE changed from 26 |
| rconnorlawson | 0:35660d7952f7 | 21 | wave_player waver(&DACout); |
| rconnorlawson | 0:35660d7952f7 | 22 | |
| rconnorlawson | 0:35660d7952f7 | 23 | // Some hardware also needs to have functions called before it will set up |
| rconnorlawson | 0:35660d7952f7 | 24 | // properly. Do that here. |
| rconnorlawson | 0:35660d7952f7 | 25 | int hardware_init() |
| rconnorlawson | 0:35660d7952f7 | 26 | { |
| rconnorlawson | 0:35660d7952f7 | 27 | // Crank up the speed |
| rconnorlawson | 0:35660d7952f7 | 28 | uLCD.baudrate(3000000); |
| rconnorlawson | 0:35660d7952f7 | 29 | pc.baud(115200); |
| rconnorlawson | 0:35660d7952f7 | 30 | |
| rconnorlawson | 0:35660d7952f7 | 31 | //Initialize pushbuttons |
| rconnorlawson | 0:35660d7952f7 | 32 | button1.mode(PullUp); |
| rconnorlawson | 0:35660d7952f7 | 33 | button2.mode(PullUp); |
| rconnorlawson | 0:35660d7952f7 | 34 | button3.mode(PullUp); |
| rconnorlawson | 0:35660d7952f7 | 35 | |
| rconnorlawson | 0:35660d7952f7 | 36 | return ERROR_NONE; |
| rconnorlawson | 0:35660d7952f7 | 37 | } |
| rconnorlawson | 0:35660d7952f7 | 38 | |
| rconnorlawson | 0:35660d7952f7 | 39 | GameInputs read_inputs() |
| rconnorlawson | 0:35660d7952f7 | 40 | { |
| rconnorlawson | 0:35660d7952f7 | 41 | GameInputs in; |
| trich9 | 4:2297a714936f | 42 | //b1 = pin23 |
| trich9 | 4:2297a714936f | 43 | //b2 = pin22 |
| trich9 | 4:2297a714936f | 44 | //b3 = pin21 |
| trich9 | 4:2297a714936f | 45 | //MYCODE |
| trich9 | 4:2297a714936f | 46 | in.b1 = button3; |
| trich9 | 4:2297a714936f | 47 | in.b2 = button2; |
| trich9 | 4:2297a714936f | 48 | in.b3 = button1; |
| trich9 | 4:2297a714936f | 49 | |
| trich9 | 4:2297a714936f | 50 | acc.readXYZGravity(&in.ax,&in.ay,&in.az); |
| trich9 | 4:2297a714936f | 51 | |
| trich9 | 4:2297a714936f | 52 | //pc.printf("ax - %f ay - %f az - %f\n",in.ax,in.ay,in.az); |
| trich9 | 4:2297a714936f | 53 | //ENDMYCODE |
| rconnorlawson | 0:35660d7952f7 | 54 | return in; |
| rconnorlawson | 0:35660d7952f7 | 55 | } |