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 // Copyright 2020 Georgia Tech. All rights reserved. 00002 // The materials provided by the instructor in this course are for 00003 // the use of the students currently enrolled in the course. 00004 // Copyrighted course materials may not be further disseminated. 00005 // This file must not be made publicly available anywhere. 00006 00007 // This header has all the (extern) declarations of the globals. 00008 // "extern" means "this is instantiated somewhere, but here's what the name 00009 // means. 00010 #include "globals.h" 00011 00012 #include "hardware.h" 00013 #include "Speaker.h" 00014 // We need to actually instantiate all of the globals (i.e. declare them once 00015 // without the extern keyword). That's what this file does! 00016 00017 // Hardware initialization: Instantiate all the things! 00018 uLCD_4DGL uLCD(p9,p10,p11); // LCD Screen (tx, rx, reset) 00019 //SDFileSystem sd(p5, p6, p7, p8, "sd"); // SD Card(mosi, miso, sck, cs) 00020 Serial pc(USBTX,USBRX); // USB Console (tx, rx) 00021 MMA8452 acc(p28, p27, 100000); // Accelerometer (sda, sdc, rate) 00022 DigitalIn button1(p21); // Pushbuttons (pin) 00023 DigitalIn button2(p22); 00024 DigitalIn button3(p23); 00025 AnalogOut DACout(p18); // Speaker (pin) 00026 PwmOut speaker(p26); 00027 wave_player waver(&DACout); 00028 00029 00030 // Some hardware also needs to have functions called before it will set up 00031 // properly. Do that here. 00032 00033 int hardware_init() 00034 { 00035 // Crank up the speed 00036 uLCD.baudrate(3000000); 00037 pc.baud(115200); 00038 00039 //Initialize pushbuttons 00040 button1.mode(PullUp); 00041 button2.mode(PullUp); 00042 button3.mode(PullUp); 00043 00044 return ERROR_NONE; 00045 } 00046 00047 // Implement this function. 00048 // HINT: lookup your accelerometer under mbed site > Hardware> Components 00049 // and look at demo code 00050 GameInputs read_inputs() 00051 { 00052 GameInputs in; 00053 00054 // Read the values and store them in in 00055 //tilting board left = -x 00056 //tilting board down towards table = +y 00057 00058 in.b1 = button3; //top button on breadboard is connected to p23 00059 in.b2 = button2; //middle button on breadboard is connected to p22 00060 in.b3 = button1; //bottom button ob breadboard is connected to p21 00061 00062 acc.readXGravity(&in.ax); 00063 acc.readYGravity(&in.ay); 00064 acc.readZGravity(&in.az); 00065 00066 //pc.printf("xAccel: %f yAccel: %f zAccel: %f\n",in.ax,in.ay,in.az); 00067 return in; 00068 } 00069
Generated on Mon Aug 1 2022 15:08:58 by
