SNAKE GAME

Dependencies:   mbed wave_player 4DGL-uLCD-SE MMA8452

Committer:
congvu
Date:
Wed Nov 25 04:25:25 2020 +0000
Revision:
0:24041b847eb5
ECE2035 SNAKE GAME;

Who changed what in which revision?

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