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 button3.mode(PullUp); 00037 acc.activate(); 00038 return ERROR_NONE; 00039 } 00040 00041 GameInputs read_inputs() 00042 { 00043 GameInputs in; 00044 00045 in.b1 = button1; // top button 00046 in.b2 = button2; // second button 00047 in.b3 = button3; // third button 00048 in.b4 = button4; // fourth, run button 00049 acc.readXGravity(&in.ax); // x axis acce 00050 acc.readYGravity(&in.ay); // y axis acce 00051 acc.readZGravity(&in.az); // z axis acce 00052 return in; 00053 }
Generated on Thu Jul 14 2022 01:43:17 by
1.7.2