P2-2 Harris Barton

Dependencies:   mbed wave_player 4DGL-uLCD-SE MMA8452

Committer:
hbarton7
Date:
Wed Nov 25 01:17:39 2020 +0000
Revision:
3:e2fb359d6545
Parent:
2:4947d6a82971
P2-2 Harris Barton;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
DCchico 2:4947d6a82971 1 // Copyright 2020 Georgia Tech. All rights reserved.
DCchico 2:4947d6a82971 2 // The materials provided by the instructor in this course are for
DCchico 2:4947d6a82971 3 // the use of the students currently enrolled in the course.
DCchico 2:4947d6a82971 4 // Copyrighted course materials may not be further disseminated.
DCchico 2:4947d6a82971 5 // This file must not be made publicly available anywhere.
DCchico 2:4947d6a82971 6
DCchico 1:10330bce85cb 7 // This header has all the (extern) declarations of the globals.
DCchico 1:10330bce85cb 8 // "extern" means "this is instantiated somewhere, but here's what the name
DCchico 1:10330bce85cb 9 // means.
DCchico 1:10330bce85cb 10 #include "globals.h"
DCchico 1:10330bce85cb 11
DCchico 1:10330bce85cb 12 #include "hardware.h"
DCchico 1:10330bce85cb 13
DCchico 1:10330bce85cb 14 // We need to actually instantiate all of the globals (i.e. declare them once
DCchico 1:10330bce85cb 15 // without the extern keyword). That's what this file does!
DCchico 1:10330bce85cb 16
DCchico 1:10330bce85cb 17 // Hardware initialization: Instantiate all the things!
DCchico 1:10330bce85cb 18 uLCD_4DGL uLCD(p9,p10,p11); // LCD Screen (tx, rx, reset)
DCchico 1:10330bce85cb 19 //SDFileSystem sd(p5, p6, p7, p8, "sd"); // SD Card(mosi, miso, sck, cs)
DCchico 1:10330bce85cb 20 Serial pc(USBTX,USBRX); // USB Console (tx, rx)
DCchico 1:10330bce85cb 21 MMA8452 acc(p28, p27, 100000); // Accelerometer (sda, sdc, rate)
DCchico 1:10330bce85cb 22 DigitalIn button1(p21); // Pushbuttons (pin)
DCchico 1:10330bce85cb 23 DigitalIn button2(p22);
DCchico 1:10330bce85cb 24 DigitalIn button3(p23);
DCchico 1:10330bce85cb 25 AnalogOut DACout(p18); // Speaker (pin)
DCchico 1:10330bce85cb 26 PwmOut speaker(p26);
DCchico 1:10330bce85cb 27 wave_player waver(&DACout);
DCchico 1:10330bce85cb 28
DCchico 1:10330bce85cb 29
DCchico 1:10330bce85cb 30 // Some hardware also needs to have functions called before it will set up
DCchico 1:10330bce85cb 31 // properly. Do that here.
hbarton7 3:e2fb359d6545 32
DCchico 1:10330bce85cb 33 int hardware_init()
DCchico 1:10330bce85cb 34 {
DCchico 1:10330bce85cb 35 // Crank up the speed
DCchico 1:10330bce85cb 36 uLCD.baudrate(3000000);
DCchico 1:10330bce85cb 37 pc.baud(115200);
DCchico 1:10330bce85cb 38
DCchico 1:10330bce85cb 39 //Initialize pushbuttons
DCchico 1:10330bce85cb 40 button1.mode(PullUp);
DCchico 1:10330bce85cb 41 button2.mode(PullUp);
DCchico 1:10330bce85cb 42 button3.mode(PullUp);
DCchico 1:10330bce85cb 43
DCchico 1:10330bce85cb 44 return ERROR_NONE;
DCchico 1:10330bce85cb 45 }
DCchico 1:10330bce85cb 46
DCchico 2:4947d6a82971 47 // Implement this function.
DCchico 2:4947d6a82971 48 // HINT: lookup your accelerometer under mbed site > Hardware> Components
DCchico 2:4947d6a82971 49 // and look at demo code
DCchico 1:10330bce85cb 50 GameInputs read_inputs()
DCchico 1:10330bce85cb 51 {
DCchico 1:10330bce85cb 52 GameInputs in;
hbarton7 3:e2fb359d6545 53
hbarton7 3:e2fb359d6545 54 // Read the values and store them in in
hbarton7 3:e2fb359d6545 55 //tilting board left = -x
hbarton7 3:e2fb359d6545 56 //tilting board down towards table = +y
hbarton7 3:e2fb359d6545 57
hbarton7 3:e2fb359d6545 58 in.b1 = button3; //top button on breadboard is connected to p23
hbarton7 3:e2fb359d6545 59 in.b2 = button2; //middle button on breadboard is connected to p22
hbarton7 3:e2fb359d6545 60 in.b3 = button1; //bottom button ob breadboard is connected to p21
hbarton7 3:e2fb359d6545 61
hbarton7 3:e2fb359d6545 62 acc.readXGravity(&in.ax);
hbarton7 3:e2fb359d6545 63 acc.readYGravity(&in.ay);
hbarton7 3:e2fb359d6545 64 acc.readZGravity(&in.az);
hbarton7 3:e2fb359d6545 65
hbarton7 3:e2fb359d6545 66 //pc.printf("xAccel: %f yAccel: %f zAccel: %f\n",in.ax,in.ay,in.az);
DCchico 1:10330bce85cb 67 return in;
DCchico 1:10330bce85cb 68 }