Su 200943147

Dependencies:   Gamepad N5110 mbed

Committer:
GS00
Date:
Thu May 04 13:28:46 2017 +0000
Revision:
8:3899d883d329
Parent:
7:31dd8865cc44
Child:
9:6ee4c806f3e9
Final

Who changed what in which revision?

UserRevisionLine numberNew contents of line
GS00 0:444b4d0a113d 1 #include "mbed.h"
GS00 0:444b4d0a113d 2 #include "N5110.h"
GS00 3:9dd35424cdfe 3 #include "Engine.h"
GS00 3:9dd35424cdfe 4 #include "Gamepad.h"
GS00 0:444b4d0a113d 5
GS00 3:9dd35424cdfe 6 struct UserInput {
GS00 3:9dd35424cdfe 7 Direction d;
GS00 3:9dd35424cdfe 8 };
GS00 3:9dd35424cdfe 9
GS00 8:3899d883d329 10 //////////////////Object////////////////////
GS00 0:444b4d0a113d 11 N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
GS00 3:9dd35424cdfe 12 Gamepad pad;
GS00 3:9dd35424cdfe 13 Engine Engine;
GS00 8:3899d883d329 14 ///////////////Function////////////////////
GS00 3:9dd35424cdfe 15 void Init();
GS00 8:3899d883d329 16 void WelcometoStart();
GS00 0:444b4d0a113d 17
GS00 8:3899d883d329 18 ///////////////MainLoop/////////////////////
GS00 3:9dd35424cdfe 19 int main()
GS00 3:9dd35424cdfe 20 {
GS00 3:9dd35424cdfe 21 Init();
GS00 8:3899d883d329 22 WelcometoStart();
GS00 8:3899d883d329 23
GS00 8:3899d883d329 24 int fps = 4; //4 frames per second
GS00 8:3899d883d329 25 wait(1.0f/fps);
GS00 8:3899d883d329 26
GS00 8:3899d883d329 27 // game loop - read input, update the game state and screen display
GS00 3:9dd35424cdfe 28 while (1) {
GS00 3:9dd35424cdfe 29 Engine.ReadInput(pad);
GS00 8:3899d883d329 30 Engine.Update(lcd,pad);
GS00 3:9dd35424cdfe 31 Engine.Pixel(lcd);
GS00 8:3899d883d329 32 wait(1.0f/fps);
GS00 3:9dd35424cdfe 33 }
GS00 3:9dd35424cdfe 34 }
GS00 3:9dd35424cdfe 35
GS00 3:9dd35424cdfe 36 void Init()
GS00 3:9dd35424cdfe 37 {
GS00 8:3899d883d329 38 // initialise the LCD and Gamepad
GS00 3:9dd35424cdfe 39 lcd.init();
GS00 3:9dd35424cdfe 40 pad.init();
GS00 8:3899d883d329 41 lcd.normalMode(); // normal colour mode
GS00 8:3899d883d329 42 lcd.setBrightness(0.5); // put LED backlight on 50%
GS00 3:9dd35424cdfe 43
GS00 3:9dd35424cdfe 44 // initialise the game
GS00 5:afa6592a4ba5 45 Engine.Init(lcd);
GS00 3:9dd35424cdfe 46 }
GS00 6:e919a1fd1eed 47
GS00 8:3899d883d329 48 void WelcometoStart()
GS00 8:3899d883d329 49 {
GS00 8:3899d883d329 50 lcd.printString(" Welcome ",0,2);
GS00 8:3899d883d329 51 lcd.printString(" Tetris ",0,3);
GS00 8:3899d883d329 52 lcd.printString(" Press Start ",0,5);
GS00 6:e919a1fd1eed 53 lcd.refresh();
GS00 8:3899d883d329 54
GS00 8:3899d883d329 55 // flashing LEDs until start button is pressed
GS00 6:e919a1fd1eed 56 while ( pad.check_event(Gamepad::START_PRESSED) == false) {
GS00 8:3899d883d329 57 for(int a=0; a<7; a++) {
GS00 8:3899d883d329 58 pad.led(a,1); //led on from left to right
GS00 8:3899d883d329 59 wait(0.1); //time delay
GS00 8:3899d883d329 60 }
GS00 8:3899d883d329 61 for(int a=6; a>0; a--) {
GS00 8:3899d883d329 62 pad.led(a,0); //led off from right to left
GS00 8:3899d883d329 63 wait(0.1); //time delay
GS00 8:3899d883d329 64 }
GS00 6:e919a1fd1eed 65 }
GS00 6:e919a1fd1eed 66 }