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
00001 // This header has all the (extern) declarations of the globals. 00002 // "extern" means "this is instantiated somewhere, but here's what the name 00003 // means. 00004 #include "globals.h" 00005 00006 #include "hardware.h" 00007 00008 // We need to actually instantiate all of the globals (i.e. declare them once 00009 // without the extern keyword). That's what this file does! 00010 00011 // Hardware initialization: Instantiate all the things! 00012 uLCD_4DGL uLCD(p9,p10,p11); // LCD Screen (tx, rx, reset) 00013 SDFileSystem sd(p5, p6, p7, p8, "sd"); // SD Card(mosi, miso, sck, cs) 00014 Serial pc(USBTX,USBRX); // USB Console (tx, rx) 00015 MMA8452 acc(p28, p27, 100000); // Accelerometer (sda, sdc, rate) 00016 DigitalIn button1(p21); // Pushbuttons (pin) 00017 DigitalIn button2(p22); 00018 DigitalIn button3(p23); 00019 DigitalIn button4(p24); 00020 AnalogOut DACout(p18); // Speaker (pin) 00021 PwmOut speaker(p26); 00022 wave_player waver(&DACout); 00023 00024 // Some hardware also needs to have functions called before it will set up 00025 // properly. Do that here. 00026 int hardware_init() 00027 { 00028 // Crank up the speed 00029 uLCD.baudrate(3000000); 00030 pc.baud(115200); 00031 00032 //Initialize pushbuttons 00033 button1.mode(PullUp); 00034 button2.mode(PullUp); 00035 button3.mode(PullUp); 00036 button4.mode(PullUp); 00037 return ERROR_NONE; 00038 } 00039 00040 GameInputs read_inputs() 00041 { 00042 GameInputs in; 00043 in.b1 = button1; 00044 in.b2 = button2; 00045 in.b3 = button3; 00046 in.b4 = button4; 00047 acc.readXGravity(&in.ax); 00048 acc.readYGravity(&in.ay); 00049 acc.readZGravity(&in.az); 00050 //pc.printf("%d,%d,%d\r\n",in.ax,in.ay,in.az); 00051 return in; 00052 }
Generated on Sun Jul 24 2022 01:39:03 by
1.7.2