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: mbed
Diff: main.cpp
- Revision:
- 12:cb3a81adf48b
- Parent:
- 10:3958fb08696d
- Child:
- 15:3a65925ac561
diff -r c4b740a970f8 -r cb3a81adf48b main.cpp
--- a/main.cpp Sat May 23 10:50:43 2020 +0000
+++ b/main.cpp Sun May 24 14:19:21 2020 +0000
@@ -28,32 +28,27 @@
//
#define HEAD_SIZE 1
-#define HEAD_SPEED 2
+#define HEAD_SPEED 3
void welcome();
void init();
+void render();
int main()
{
- int fps = 6;
- //initialise objects
+ //set frames per second
+ int fps = 4;
+ //initialise objects
init();
- engine.init(HEAD_SIZE, HEAD_SPEED);
- //head.init(1,3);
-
- //render first frame
-
+ //display simple start screen and wai for user to press start
welcome();
- wait(3.0);
-
- lcd.clear();
- //head.draw(lcd);
- lcd.refresh();
-
+ //clear lcd and render first frame
+ render();
+ //while one loop so keep keeps running
while(1) {
- /*
+ /* Debugging print statements to ensure gamepad joystick was getting the correct direction
if (_d == N) {
printf("North\n");
} else if (_d == NE) {
@@ -79,17 +74,11 @@
printf("start not pressed\n");
}*/
-
engine.read_input(pad);
engine.update(pad, lcd);
- lcd.clear();
- engine.draw(lcd);
- lcd.refresh();
+ render();
+ wait(1.0f/fps);
-
-
-
- wait(1.0f/fps);
}
@@ -98,25 +87,33 @@
void welcome() {
-
- lcd.printString(" SNAKE! ",0,1);
+ //print simple display message
+ lcd.printString(" SNAKE! ",0,1);
+ lcd.printString(" Press Start ", 0, 3);
lcd.refresh();
- /* wait flashing LEDs until start button is pressed (start pressed function does not seem ot be working as expected
- while ( pad.start_pressed() == false) {
+ //wait flashing LEDs until start button is pressed
+ while ( pad.start_held() == false) {
lcd.setContrast( pad.read_pot1());
pad.leds_on();
wait(0.1);
pad.leds_off();
wait(0.1);
- } */
+ }
}
-
+//function to initialise all objects
void init() {
lcd.init();
pad.init();
+ engine.init(HEAD_SIZE, HEAD_SPEED);
+}
+//function to render the image in screen
+void render()
+{
+ lcd.clear();
+ engine.draw(lcd);
+ lcd.refresh();
}
-