11
Dependencies: mbed N5110 Joystick
Diff: gaming/gaming.cpp
- Revision:
- 2:4fd751cc1af7
- Parent:
- 0:283702b9a078
--- a/gaming/gaming.cpp Fri Apr 09 07:00:20 2021 +0000 +++ b/gaming/gaming.cpp Wed Apr 14 14:12:26 2021 +0000 @@ -0,0 +1,50 @@ +#include "gaming.h" +#include "lcd.h" + + +AnalogIn ldr(p15); +N5110 lcd(p8,p9,p10,p11,p13,p21); + +AnalogIn joy_v(p20); +AnalogIn joy_h(p19); +AnalogIn joy_button(p17); + +void main() { + + lcd.init(); + lcd_clear(); + //while(1) { + //int x0 = rand()%45+20;//随机产生20-64的随机整数,终止值是45-1+20=64 + int x0 = 42; + int y0 = 0; + //float y0 = 1; + //lcd.drawRect(x0,y0,5,5,FILL_TRANSPARENT);//中空 + square(x0,y0); + background(); + lcd_refresh(); + wait(1); + while (1) { + lcd_clear(); + background(); + //joystick.init(); + float x1 = joy_h.read(); + if (x1 < 0.45){ + x1 = 0; } + else if (x1 > 0.55) { + x1 = 1; } + else + x1 = 0.5; //强制取整数 + x0 = x0 + 2*(0.5-x1); + y0 = y0 + 1; + square(x0,y0); + // judge the boundary + + + lcd_refresh(); + + wait(0.8); + if (y0 == 44) + break; + } + +}