11
Dependencies: mbed N5110 Joystick
Revision 2:4fd751cc1af7, committed 2021-04-14
- Comitter:
- lhyr
- Date:
- Wed Apr 14 14:12:26 2021 +0000
- Parent:
- 1:77e6588be25b
- Commit message:
- 1
Changed in this revision
diff -r 77e6588be25b -r 4fd751cc1af7 LCD/lcd.cpp --- a/LCD/lcd.cpp Fri Apr 09 07:00:20 2021 +0000 +++ b/LCD/lcd.cpp Wed Apr 14 14:12:26 2021 +0000 @@ -14,6 +14,7 @@ void lcd_clear() { lcd.clear(); } +/********************** start *******************/ void print_menu() { lcd.printString("Tetris",25,0); lcd.printString("Press button A",0,1); @@ -46,3 +47,11 @@ }; lcd.drawSprite(19,26,5,3,(int*)T1); } +/*********************** gaming ***************************/ +void square(int &x0, int &y0) { + lcd.drawRect(x0,y0,4,4,FILL_BLACK); +} +void background () { + lcd.drawRect(29,0,2,48,FILL_BLACK); + lcd.drawRect(54,0,2,48,FILL_BLACK); +}
diff -r 77e6588be25b -r 4fd751cc1af7 LCD/lcd.h --- a/LCD/lcd.h Fri Apr 09 07:00:20 2021 +0000 +++ b/LCD/lcd.h Wed Apr 14 14:12:26 2021 +0000 @@ -6,10 +6,15 @@ void lcd_init(); void lcd_refresh(); void lcd_clear(); +/********************* start *******************/ void print_menu(); void print_GUI(); void upper_T1(); void lower_T1(); +/********************* gaming *******************/ +/********************** block ********************/ +void square(int &x0, int &y0); +void background(); #endif \ No newline at end of file
diff -r 77e6588be25b -r 4fd751cc1af7 block/block.cpp
diff -r 77e6588be25b -r 4fd751cc1af7 block/block.h
diff -r 77e6588be25b -r 4fd751cc1af7 break/break.cpp --- a/break/break.cpp Fri Apr 09 07:00:20 2021 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,8 +0,0 @@ -#include "mbed.h" -#include "break.h" - - - - - -void example(int a){a++;} \ No newline at end of file
diff -r 77e6588be25b -r 4fd751cc1af7 break/break.h --- a/break/break.h Fri Apr 09 07:00:20 2021 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,18 +0,0 @@ -#ifndef BREAK_H -#define BREAK_H - -void buttonA_isr(); -void buttonB_isr(); -void buttonD_isr(); -void rise_A(); -void rise_B(); -void rise_D(); -void Tick(); - - - -extern volatile int button_a_flag; -extern volatile int button_b_flag; -extern volatile int button_d_flag; - -#endif \ No newline at end of file
diff -r 77e6588be25b -r 4fd751cc1af7 gaming/gaming.cpp --- 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; + } + +}
diff -r 77e6588be25b -r 4fd751cc1af7 gaming/gaming.h --- a/gaming/gaming.h Fri Apr 09 07:00:20 2021 +0000 +++ b/gaming/gaming.h Wed Apr 14 14:12:26 2021 +0000 @@ -0,0 +1,11 @@ +#ifndef GAMING_H +#define GAMING_H + +// include the different header files + +#include "mbed.h" +#include "Joystick.h" + +void gaming(); + +#endif \ No newline at end of file
diff -r 77e6588be25b -r 4fd751cc1af7 main.cpp --- a/main.cpp Fri Apr 09 07:00:20 2021 +0000 +++ b/main.cpp Wed Apr 14 14:12:26 2021 +0000 @@ -11,10 +11,10 @@ DigitalOut led(LED1); Ticker flipper; -volatile int button_a_flag; -volatile int button_b_flag; -volatile int button_d_flag; -volatile int button_c_flag; +int button_a_flag; +int button_b_flag; +int button_d_flag; +int button_c_flag; DigitalOut led1(LED1); void buttonA_isr(); @@ -48,14 +48,14 @@ if (button_c_flag) { button_c_flag = 0; led1 = !led1; - select11(button_a_flag,button_d_flag,button_b_flag); + select11(&button_a_flag,&button_d_flag,&button_b_flag); } } } -void buttonA_isr(*button_a_flag) +void buttonA_isr() { button_a_flag = 1; // set flag in ISR }
diff -r 77e6588be25b -r 4fd751cc1af7 start/start.cpp --- a/start/start.cpp Fri Apr 09 07:00:20 2021 +0000 +++ b/start/start.cpp Wed Apr 14 14:12:26 2021 +0000 @@ -1,7 +1,8 @@ #include "start.h" #include "lcd.h" +#include "gaming.h" -void select11( int *button_a_flag, int *button_d_flag,int *button_b_flag) { +void select11( int *button_a_flag, int *button_d_flag,int *button_b_flag) { //函数定义 int x = 19,y = 18; DigitalOut led2(LED2); while(1) { @@ -13,8 +14,8 @@ led2=button_b_flag[0]; while(1){ - if (button_b_flag){ - button_b_flag = 0; + if (*button_b_flag){ + *button_b_flag = 0; led2=!led2; y = 18; lcd_clear(); @@ -23,8 +24,8 @@ lcd_refresh(); } - if (button_d_flag){ - button_d_flag = 0; + if (*button_d_flag){ + *button_d_flag = 0; y = 26; lcd_clear(); print_GUI(); @@ -32,12 +33,12 @@ lcd_refresh(); } - if (button_a_flag && y == 18){ - button_a_flag = 0; - //gaming(); + if (*button_a_flag && y == 18){ + *button_a_flag = 0; + gaming(); } - if (button_a_flag && y == 26){ - button_a_flag = 0; + if (*button_a_flag && y == 26){ + *button_a_flag = 0; print_menu(); } }//第二个while
diff -r 77e6588be25b -r 4fd751cc1af7 start/start.h --- a/start/start.h Fri Apr 09 07:00:20 2021 +0000 +++ b/start/start.h Wed Apr 14 14:12:26 2021 +0000 @@ -6,7 +6,7 @@ // include the different header files -void select11( int *button_a_flag, int *button_d_flag,int *button_b_flag); +void select11( int *button_a_flag, int *button_d_flag,int *button_b_flag); //函数声明