hongyun AHN / Mbed 2 deprecated Project_MaZe1_copy

Dependencies:   Gamepad N5110 mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 
00002 #include "mbed.h"
00003 #include "Gamepad.h"
00004 #include "N5110.h"
00005 #include "Background.h"
00006 
00007 
00008 
00009 struct UserInput {
00010     Direction d;
00011     float mag;
00012 };
00013 
00014 N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
00015 Gamepad pad;
00016 Background back;
00017 
00018 void init();
00019 void update_game(UserInput input);
00020 void render();
00021 void welcome();
00022 
00023 int main()
00024 {
00025     int fps = 8;  
00026 
00027     init();
00028     welcome();
00029     
00030     render();  
00031     wait(1.0f/fps);  
00032 
00033    
00034     while (1) {
00035         back.read_input(pad);
00036         back.update(pad,lcd);
00037         render();
00038         wait(1.0f/fps);
00039     }
00040 }
00041 
00042 void init()
00043 {
00044     lcd.init();
00045     pad.init();
00046      
00047    back.init();
00048 
00049 }
00050 
00051 void render()
00052 {
00053  
00054     lcd.clear();  
00055     back.draw(lcd);
00056     lcd.refresh();
00057 }
00058 
00059 void welcome() {
00060     
00061     lcd.printString("     MAZE    ",0,2);  
00062     lcd.printString("  Press Start ",0,5);
00063     lcd.refresh();
00064      
00065   
00066     while ( pad.check_event(Gamepad::START_PRESSED) == false) {
00067         pad.leds_on();
00068         wait(0.3);
00069         pad.leds_off();
00070         wait(0.2);
00071     }
00072  
00073 }