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
main.cpp
00001 /* 00002 ELEC2645 Embedded Systems Project 00003 School of Electronic & Electrical Engineering 00004 University of Leeds 00005 00006 Name: Jiaxin Zhou 00007 Username: Jiaxin Zhou 00008 Student ID Number: 201282650 00009 Date:16/04/2019 00010 00011 */ 00012 00013 #include "mbed.h" 00014 #include "Gamepad.h" 00015 #include "N5110.h" 00016 #include "Move.h" 00017 #include "Menu.h" 00018 /** @file main.cpp 00019 * @brief This file is used to callback all functions. 00020 */ 00021 00022 N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); 00023 Gamepad pad; 00024 Move move; 00025 Menu menu; 00026 00027 void initial(); 00028 void welcome(); 00029 void render(); 00030 void menus(N5110 &lcd); 00031 int input(int sel,Gamepad &pad); 00032 00033 ///////////// MAIN.CPP //////////////// 00034 int main () { 00035 int fps = 0; // initial fps, fps will be update by function menu.difficulty(lcd,pad). 00036 initial(); 00037 welcome(); 00038 menu.menus(lcd,pad);// settings or start game 00039 fps = menu.difficulty(lcd,pad); 00040 render(); 00041 move.getfood(); // generate food 00042 while(1) { 00043 00044 move.eatfood(); //check is food is hit by snake head, if yes , generate a new one 00045 move.update(pad); 00046 move.updatebody(); 00047 00048 render(); 00049 move.die(lcd,pad); 00050 wait(1.0f/fps); 00051 } 00052 00053 00054 } 00055 00056 void initial() { 00057 lcd.init(); 00058 pad.init(); 00059 move.initial(); 00060 } 00061 00062 void render() 00063 { 00064 // clear screen, re-draw and refresh 00065 lcd.clear(); 00066 move.onlcd(lcd); 00067 lcd.refresh(); 00068 } 00069 00070 void welcome() { 00071 lcd.printString(" snake! ",0,1); 00072 lcd.printString("( Press Start)",0,4); 00073 lcd.refresh(); 00074 00075 while ( pad.check_event(Gamepad::START_PRESSED) == false) { 00076 pad.leds_on(); 00077 wait(0.1); 00078 pad.leds_off(); 00079 wait(0.1); 00080 } 00081 00082 }
Generated on Tue Jul 12 2022 22:27:32 by
1.7.2