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: N5110 PowerControl mbed
Diff: main.cpp
- Revision:
- 13:098319060433
- Parent:
- 12:3f4d9cb7dd8a
- Child:
- 14:883a86f009fd
--- a/main.cpp Mon Apr 27 12:17:32 2015 +0000 +++ b/main.cpp Mon Apr 27 16:01:37 2015 +0000 @@ -1,21 +1,24 @@ #include "mbed.h" #include "N5110.h" #define DIRECTION_TOLERANCE 0.1// Tolerance of Joystick - +#include "tone.h" +#define PI 3.14159265359 +#include "PowerControl/PowerControl.h" +#include "PowerControl/EthernetPowerControl.h" BusOut myleds(p24,p23,p22); //External LEDS -InterruptIn StartButton(p18);//Start button + N5110 lcd(p7,p8,p9,p10,p11,p13,p26); //PWR, SCE, RST, DC, MOSI, SCLK, LED AnalogIn bright(p20);//Pot to adjust brightness -Ticker timer; //Create ticker object +Timeout timer; //Create ticker object DigitalIn Jbutton(p17);// Joystick Button AnalogIn xPot(p15);// Joystick x-direction AnalogIn yPot(p16);// Joystick y-direction int i=3; // Pacman's starting position int j = 3; -int buttonflag=0; // flag for pause button +int buttonflag=0; // flag for pause button InterruptIn button(p18);//Pause button Ticker pollJoystick; // timer to regularly read the joystick - +int timerflag=0; int coinflag = 1; int coinflag2 = 1; int coinflag3 = 1; @@ -95,31 +98,56 @@ } - -void pressPause() +void timerExpired() // ISR for timeout function { - buttonflag=!buttonflag;// set button flag + timerflag=1; + + } + +void pressPause()// Interrupt Service Routine (ISR) for pause button +{ + buttonflag=!buttonflag;// set button flag +} + + + + + void pause() { - button.rise(&pressPause); // event generated on rising edge - while (buttonflag){ - lcd.clear(); - lcd.printString("Pause", 25,21); - - - - + timer.attach(&timerExpired,3.0);// Call timeout after 20 seconds + button.rise(&pressPause); // event generated on rising edge + while (buttonflag) { + lcd.clear(); + lcd.printString("Pause", 25,21); + while (timerflag){ + timer.detach(); + lcd.turnOff(); + Sleep(); + if (!buttonflag){ + timerflag=0; + lcd.init(); + } + + + + } - - } - +} + + +} + + - - - -} + + + + + + void drawMap() { @@ -201,7 +229,7 @@ d++; if(lcd.getPixel (i-1,j+4)) d++; - if(lcd.getPixel (i-2,j+4)) + if(lcd.getPixel (i-2,j+4)) d++; if (d>=4) { // Condition for solid obstacles j--; @@ -271,18 +299,18 @@ } if (coinflag19) { lcd.drawCircle(62,24,2,0); //Coin 3.5 - + } - + if (coinflag20) { lcd.drawCircle(74,24,2,0); //Coin 3.6 } - if (coinflag21) { + if (coinflag21) { lcd.drawCircle(15,15,2,0);//Coin 2.1 - } - if (coinflag22) { + } + if (coinflag22) { lcd.drawCircle(65,15,2,0);//Coin 2.3 - } + } } void checkCoin() @@ -564,11 +592,13 @@ lcd.init(); calibrateJoystick(); // get centred values of joystick pollJoystick.attach(&updateJoystick,1.0/10.0); // read joystick 10 times per second - + PHY_PowerDown(); + while(1) { lcd.setBrightness(bright); lcd.clear(); pause(); + drawPacman(); drawMap(); drawCoin();