My ELEC2645 project. Nikollao Sulollari. 200804685
Dependencies: N5110 SoftPWM mbed
main.cpp
- Committer:
- Nikollao
- Date:
- 2016-04-28
- Revision:
- 12:f591f1965abd
- Parent:
- 11:53caf3d944a9
File content as of revision 12:f591f1965abd:
/** @file main.cpp @brief Game implementation */ #include "main.h" #include "stdlib.h" int main() { /*while(1) { // check if buttons are working lcd.clear(); if (g_button_flag) { lcd.printString("button is ON!",0,0); } else { lcd.printString("button is OFF!",0,0); } if (g_button1_flag) { lcd.printString("button1 is ON",0,4); lcd.refresh(); }else { lcd.printString("button1 is OFF!",0,4); lcd.refresh(); } wait(0.2); lcd.refresh(); }*/ lcd.init(); init_K64F(); init_serial(); init_game(); ///initialize game button.rise(&button_isr); ///assign rise with ISR button1.rise(&button1_isr); calibrateJoystick(); ///calibrate joystick ticker.attach(&timer_isr,0.05); ///attach ticker with ISR every 0.1 sec reset = level; ///set reset = level to check later if level has increased // buzzer.start(); //buzzer.write(0.5); //buzzer.period_ms(4); menu(); while (1) { if (g_timer_flag) { g_timer_flag = 0; ///reset flag lcd.clear(); guidance(); hero(); enemies(); obstacles(); if (heroY < -45) { ///if hero has reached the top of the screen heroY = 0; ///hero goes back to the bottom of the screen level++; ///level increases by 1 } if (heroY >= 0) { heroY = 0; } if (reset < level) { ///if level has increased reset = level; ///update reset rectX = rand() % 84; ///set the position of rect enemy rectY = 0; circleX = 0; ///set position of circle enemy circleY = rand() % 47; } pc.printf("x = %f y = %f button = %d \n",joystick.x,joystick.y,joystick.button); pc.printf("heroY = %d , heroX = %d , n = %d \n",heroY, heroX, n); } checkOverlap(); updateJoystick(); //callibrateJoystick(); lcd.refresh(); sleep(); } } void init_serial() { // set to highest baud - ensure terminal software matches pc.baud(115200); } void init_K64F() { // on-board LEDs are active-low, so set pin high to turn them off. r_led = 1; g_led = 1; b_led = 1; // since the on-board switches have external pull-ups, we should disable the internal pull-down // resistors that are enabled by default using InterruptIn sw2.mode(PullNone); sw3.mode(PullNone); button.mode(PullDown); button1.mode(PullDown); } void timer_isr () { g_timer_flag = 1; } void game_timer_isr() { g_game_timer_flag = 1; } void sw2_isr() { g_sw2_flag = 1; } void sw3_isr() { g_sw3_flag = 1; } void button_isr() { g_button_flag =1; } void button1_isr() { g_button1_flag =1; } void timeout_isr() { if (button) { pc.printf("button is pressed! \n"); } }