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 PinDetect PowerControl mbed
Fork of DocTest by
Diff: main.cpp
- Revision:
- 10:dbcb96fa049d
- Parent:
- 9:77b83754460c
diff -r 77b83754460c -r dbcb96fa049d main.cpp
--- a/main.cpp Fri May 01 08:53:21 2015 +0000
+++ b/main.cpp Fri May 08 23:47:17 2015 +0000
@@ -15,6 +15,7 @@
EASY,
MEDIUM,
HARD,
+
};
// create enumerated type (0,1 for Game Mode)
@@ -383,7 +384,7 @@
}
-void updateSnakeArray()
+void updateSnakeVector()
{
// code to prevent snake moving in opposite direction to its current path of travel
if (joystick.direction==LEFT && previousDirection==RIGHT) { // if snake is travelling right but joystick is left
@@ -468,27 +469,28 @@
void gameOverTune() //
{
- // float frequency[]={440,659};
+// float frequency[]={440,659};
//float beat[]={1,1,};
-
- Buzzer.period(1.0/(220)); // set PWM period 1/f A
-Buzzer=0.5; // set duty cycle
-wait(0.5); // wait time
-Buzzer.period(1.0/(164)); // E
-wait(0.5);//
-Buzzer=0;// set duty cycle 0
- // set PWM period
+ Buzzer.period(1.0/(220)); // set PWM period 1/f A
+ Buzzer=0.5; // set duty cycle
+ wait(0.5); // wait time
+ Buzzer.period(1.0/(164)); // E
+ wait(0.5);//
+ Buzzer=0;// set duty cycle 0
+
+ // set PWM period
}
-void eatFoodTune(){
- Buzzer.period(1.0/(440)); // set PWM period 1/f A
-Buzzer=0.5; // set duty cycle
-wait(0.1); // wait time
-Buzzer=0;// set duty cycle 0
- }
-
+void eatFoodTune()
+{
+ Buzzer.period(1.0/(440)); // set PWM period 1/f A
+ Buzzer=0.5; // set duty cycle
+ wait(0.1); // wait time
+ Buzzer=0;// set duty cycle 0
+}
+
void gameOver()
{
leds=1;
@@ -512,8 +514,8 @@
lcd.printString("Your Score" ,12,0);// print score
lcd.printString("=" ,34,1);
- int updatedScore=score;
- int length = sprintf(buffer,"%2d",updatedScore);
+
+ int length = sprintf(buffer,"%2d",score);
if (length <= 14) // if string will fit on display
lcd.printString(buffer,40,1);
@@ -578,15 +580,13 @@
// snakeY.push_back(foodY[0]+2);
break;
}
-eatFoodTune();
+ eatFoodTune();
lcd.drawRect(snakeX[0],snakeY[0],1,1,1); // draw the new tail
- int updatedScore; // to store updated score
-
-
- updatedScore= score+5; // 5 points for every food eaten
- score=updatedScore;
- int length = sprintf(buffer,"%2d",updatedScore);// print updated score to screen
+
+ score+=5; // 5 points for every food eaten
+
+ int length = sprintf(buffer,"%2d",score);// print updated score to screen
if (length <= 14) // if string will fit on display
lcd.printString(buffer,0,0);
@@ -690,19 +690,21 @@
int main()
{
- startButton.setSampleFrequency();
+ startButton.setSampleFrequency(); //for pindetect
+ button.setSampleFrequency();// for pindetect
lcd.init();
- resetButton.mode(PullDown);
+ resetButton.mode(PullDown);
startButton.mode(PullDown);
button.mode(PullDown);
- // startButton.rise(&startButtonPressed);
startButton.attach_asserted( &startButtonPressed );
resetButton.rise(&resetButtonPressed);
- button.rise(&pauseButtonPressed);
+ button.attach_asserted(&pauseButtonPressed);
displaySplash();
leds=1;
wait(4);
-
+int result = semihost_powerdown(); //USB POWERDOWN
+ PHY_PowerDown(); //ETHERNET POWERDOWN
+
while(1) {
leds=1;// red light
startUpMenu();
@@ -736,11 +738,12 @@
joystick.direction=RIGHT; // make sure when game reset that joystick is reset to right
startingSnake(); // print starting snake
randomiseFood(); // show random food
- int score=5;// initial score is 5
+ score=5;// initial score is 5
+
int length = sprintf(buffer,"%2d",score);
if (length <= 14) // if string will fit on display
lcd.printString(buffer,0,0);
- // lcd.drawRect(0,0,83,7,0);
+
lcd.refresh();
startGame.attach(&updateGameISR,gameSpeed); // start game isr speed determined by difficulty chosen
@@ -753,7 +756,7 @@
updateGameFlag=0; // reset flag
updateJoystick(); // check joystick direction
- updateSnakeArray(); // update the array
+ updateSnakeVector(); // update the Vector
for (int i=0; i<snakeX.size(); i++) { // for all elements of snake draw 2x2 image
lcd.drawRect(snakeX[i],snakeY[i],1,1,1);
@@ -772,11 +775,9 @@
}
}
-
+ sleep();
}
}
-
-
}
}
\ No newline at end of file
