Carter Montgomery / Mbed 2 deprecated 2035_Final_Project

Dependencies:   mbed wave_player 4DGL-uLCD-SE MMA8452

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers hardware.cpp Source File

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 #include "mbed.h"
00008 
00009 
00010 // We need to actually instantiate all of the globals (i.e. declare them once
00011 // without the extern keyword). That's what this file does!
00012 
00013 // Hardware initialization: Instantiate all the things!
00014 uLCD_4DGL uLCD(p9,p10,p11);             // LCD Screen (tx, rx, reset)
00015 //SDFileSystem sd(p5, p6, p7, p8, "sd");  // SD Card(mosi, miso, sck, cs)
00016 Serial pc(USBTX,USBRX);                 // USB Console (tx, rx)
00017 MMA8452 acc(p28, p27, 100000);        // Accelerometer (sda, sdc, rate)
00018 DigitalIn button1(p21);                 // Pushbuttons (pin)
00019 DigitalIn button2(p22);
00020 DigitalIn button3(p23);
00021 AnalogOut DACout(p18);                  // Speaker (pin)
00022 PwmOut speaker(p26);
00023 wave_player waver(&DACout);
00024 
00025 // Some hardware also needs to have functions called before it will set up
00026 // properly. Do that here.
00027 int hardware_init()
00028 {
00029     // Crank up the speed
00030     uLCD.baudrate(3000000);
00031     pc.baud(115200);
00032         
00033     //Initialize pushbuttons
00034     button1.mode(PullUp); 
00035     button2.mode(PullUp);
00036     button3.mode(PullUp);
00037     
00038     return ERROR_NONE;
00039 }
00040 
00041 int butt1;
00042 
00043 void debounce(){
00044     int _counter = 0;
00045     int _samples = 10;
00046     int _shadow = 0;
00047     
00048     if (!button1) { 
00049         if (_counter < _samples) _counter++; 
00050         if (_counter == _samples) _shadow = 1; 
00051     }
00052     else { 
00053         if (_counter > 0) _counter--; 
00054         if (_counter == 0) _shadow = 0; 
00055     }
00056     butt1 = _shadow;
00057 }
00058 
00059 GameInputs read_inputs() 
00060 {
00061     Ticker ticker;
00062     //ticker.attach(&debounce, 1000);
00063     GameInputs in;
00064     acc.readXGravity(&in.ax);
00065     acc.readYGravity(&in.ay);
00066     acc.readZGravity(&in.az);
00067     //uLCD.locate(1,1);
00068     //uLCD.printf("%f\n", butt1);
00069     
00070     in.b1 = button1;//butt1;
00071     in.b2 = button2;
00072     in.b3 = button3;
00073     return in;
00074 }