-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhardware.cpp
More file actions
53 lines (42 loc) · 1.51 KB
/
hardware.cpp
File metadata and controls
53 lines (42 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// This header has all the (extern) declarations of the globals.
// "extern" means "this is instantiated somewhere, but here's what the name
// means.
#include "globals.h"
#include "hardware.h"
// We need to actually instantiate all of the globals (i.e. declare them once
// without the extern keyword). That's what this file does!
// Hardware initialization: Instantiate all the things!
uLCD_4DGL uLCD(p9,p10,p11); // LCD Screen (tx, rx, reset)
//SDFileSystem sd(p5, p6, p7, p8, "sd"); // SD Card(mosi, miso, sck, cs)
Serial pc(USBTX,USBRX); // USB Console (tx, rx)
MMA8452 acc(p28, p27, 100000); // Accelerometer (sda, sdc, rate)
DigitalIn button1(p21); // Pushbuttons (pin)
DigitalIn button2(p22);
DigitalIn button3(p23);
AnalogOut DACout(p18); // Speaker (pin)
PwmOut speaker(p25);
wave_player waver(&DACout);
// Some hardware also needs to have functions called before it will set up
// properly. Do that here.
int hardware_init()
{
// Crank up the speed
uLCD.baudrate(3000000);
// pc.baud(115200);
//Initialize pushbuttons
button1.mode(PullUp);
button2.mode(PullUp);
button3.mode(PullUp);
acc.activate();
return ERROR_NONE;
}
GameInputs read_inputs()
{
GameInputs in;
// Read the values and store them in in
in.b1 = button1.read();
in.b2 = button2.read();
in.b3 = button3.read();
ASSERT_P(acc.readXYZCounts(&in.ax, &in.ay, &in.az) == ERROR_NONE, "Accelerometer reading failed!");
return in;
}