![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Projet interfaçage en licence professionnelle MECSE à l'iut de Cachan. Réalisé sur une carte STM32F746G-DISCO. Capteur utilisé: l'accéléromètre MMA8451Q piloté en i2c via les PIN PB_9 et PB_8 de la carte. Les Pin d'interruption I1 et I2 de la carte ne sont pas utilisé. Lien du capteur: https://www.gotronic.fr/art-accelerometre-3-axes-mma8451-22164.htm Datasheet du capteur : https://www.gotronic.fr/pj-1230.pdf
Dependencies: TS_DISCO_F746NG mbed LCD_DISCO_F746NG BSP_DISCO_F746NG MMA8451Q
Réalisé sur une carte STM32F746G-DISCO. Capteur utilisé: l'accéléromètre MMA8451Q piloté en i2c via les PIN PB_9 et PB_8 de la carte. Les Pin d'interruption I1 et I2 de la carte ne sont pas utilisé.
Lien du capteur: https://www.gotronic.fr/art-accelerometre-3-axes-mma8451-22164.htm Datasheet du capteur : https://www.gotronic.fr/pj-1230.pdf
main.cpp@0:88b1d5275ad7, 2019-06-04 (annotated)
- Committer:
- jgaltier98
- Date:
- Tue Jun 04 12:53:19 2019 +0000
- Revision:
- 0:88b1d5275ad7
projet interfacage
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jgaltier98 | 0:88b1d5275ad7 | 1 | #include "mbed.h" |
jgaltier98 | 0:88b1d5275ad7 | 2 | #include <stdio.h> |
jgaltier98 | 0:88b1d5275ad7 | 3 | #include <stdlib.h> |
jgaltier98 | 0:88b1d5275ad7 | 4 | #include "LCD_DISCO_F746NG.h" |
jgaltier98 | 0:88b1d5275ad7 | 5 | #include "fonts.h" |
jgaltier98 | 0:88b1d5275ad7 | 6 | #include "TS_DISCO_F746NG.h" |
jgaltier98 | 0:88b1d5275ad7 | 7 | |
jgaltier98 | 0:88b1d5275ad7 | 8 | #include "draw.h" |
jgaltier98 | 0:88b1d5275ad7 | 9 | #include "display.h" |
jgaltier98 | 0:88b1d5275ad7 | 10 | #include "accelerometre.h" |
jgaltier98 | 0:88b1d5275ad7 | 11 | |
jgaltier98 | 0:88b1d5275ad7 | 12 | #define line_speed 2 |
jgaltier98 | 0:88b1d5275ad7 | 13 | #define line_speed2 4 |
jgaltier98 | 0:88b1d5275ad7 | 14 | #define line_speed3 6 |
jgaltier98 | 0:88b1d5275ad7 | 15 | |
jgaltier98 | 0:88b1d5275ad7 | 16 | LCD_DISCO_F746NG lcd; |
jgaltier98 | 0:88b1d5275ad7 | 17 | TS_DISCO_F746NG ts; |
jgaltier98 | 0:88b1d5275ad7 | 18 | short lenght_X_hitbox = bodyX + lenght_nose; |
jgaltier98 | 0:88b1d5275ad7 | 19 | short lenght_Y_hitbox = bodyY + 2*height_wing; |
jgaltier98 | 0:88b1d5275ad7 | 20 | |
jgaltier98 | 0:88b1d5275ad7 | 21 | |
jgaltier98 | 0:88b1d5275ad7 | 22 | |
jgaltier98 | 0:88b1d5275ad7 | 23 | int main() |
jgaltier98 | 0:88b1d5275ad7 | 24 | { |
jgaltier98 | 0:88b1d5275ad7 | 25 | TS_StateTypeDef TS_State; |
jgaltier98 | 0:88b1d5275ad7 | 26 | |
jgaltier98 | 0:88b1d5275ad7 | 27 | bool hit = false; |
jgaltier98 | 0:88b1d5275ad7 | 28 | bool hit2 = false; |
jgaltier98 | 0:88b1d5275ad7 | 29 | bool hit3 = false; |
jgaltier98 | 0:88b1d5275ad7 | 30 | bool hit4 = false; |
jgaltier98 | 0:88b1d5275ad7 | 31 | bool hit5 = false; |
jgaltier98 | 0:88b1d5275ad7 | 32 | short fire_frame=0; |
jgaltier98 | 0:88b1d5275ad7 | 33 | |
jgaltier98 | 0:88b1d5275ad7 | 34 | short int score = 0,best = 0; |
jgaltier98 | 0:88b1d5275ad7 | 35 | |
jgaltier98 | 0:88b1d5275ad7 | 36 | short posX_line = 0; |
jgaltier98 | 0:88b1d5275ad7 | 37 | short posX_line2 = 0; |
jgaltier98 | 0:88b1d5275ad7 | 38 | short posX_line3 = 0; |
jgaltier98 | 0:88b1d5275ad7 | 39 | short posX_ship = 0; |
jgaltier98 | 0:88b1d5275ad7 | 40 | short posY_ship = 0; |
jgaltier98 | 0:88b1d5275ad7 | 41 | short index_star = 0; |
jgaltier98 | 0:88b1d5275ad7 | 42 | short Xaccelerate=0; |
jgaltier98 | 0:88b1d5275ad7 | 43 | short Yaccelerate=0; |
jgaltier98 | 0:88b1d5275ad7 | 44 | short speed_difficulty=0,flag_level_difficulty=0; |
jgaltier98 | 0:88b1d5275ad7 | 45 | |
jgaltier98 | 0:88b1d5275ad7 | 46 | short pos_star[10][2]={{50,47},{102,97},{49,250},{253,127},{380,142},{200,200},{150,150},{370,250},{253,200},{100,142}}; |
jgaltier98 | 0:88b1d5275ad7 | 47 | uint8_t status; |
jgaltier98 | 0:88b1d5275ad7 | 48 | bool continuer=true; |
jgaltier98 | 0:88b1d5275ad7 | 49 | status = ts.Init(lcd.GetXSize(), lcd.GetYSize()); |
jgaltier98 | 0:88b1d5275ad7 | 50 | lcd.SetBackColor(LCD_COLOR_BLACK); |
jgaltier98 | 0:88b1d5275ad7 | 51 | lcd.SetTextColor(LCD_COLOR_GREEN); |
jgaltier98 | 0:88b1d5275ad7 | 52 | lcd.Clear(LCD_COLOR_BLACK); |
jgaltier98 | 0:88b1d5275ad7 | 53 | lcd.DisplayStringAt(0, LINE(1), (uint8_t *)"welcome to", CENTER_MODE); |
jgaltier98 | 0:88b1d5275ad7 | 54 | lcd.DisplayStringAt(0, LINE(2), (uint8_t *)"ESCAPE THE LINE", CENTER_MODE); |
jgaltier98 | 0:88b1d5275ad7 | 55 | draw_load(190, LINE(7)); |
jgaltier98 | 0:88b1d5275ad7 | 56 | lcd.DisplayStringAt(0, LINE(8), (uint8_t *)"Touch to start!", CENTER_MODE); |
jgaltier98 | 0:88b1d5275ad7 | 57 | while(continuer){ |
jgaltier98 | 0:88b1d5275ad7 | 58 | ts.GetState(&TS_State); |
jgaltier98 | 0:88b1d5275ad7 | 59 | if(TS_State.touchDetected)continuer=false; |
jgaltier98 | 0:88b1d5275ad7 | 60 | } |
jgaltier98 | 0:88b1d5275ad7 | 61 | |
jgaltier98 | 0:88b1d5275ad7 | 62 | lcd.DisplayStringAt(0, LINE(0), (uint8_t *)"Escape the line v1.0", LEFT_MODE); |
jgaltier98 | 0:88b1d5275ad7 | 63 | lcd.DrawHLine(0,YMIN,480); |
jgaltier98 | 0:88b1d5275ad7 | 64 | lcd.DrawVLine(XMAX,YMIN,YMAX-YMIN); |
jgaltier98 | 0:88b1d5275ad7 | 65 | lcd.DisplayStringAt(XMAX+2, YMIN+2, (uint8_t *)"Score",LEFT_MODE); |
jgaltier98 | 0:88b1d5275ad7 | 66 | display_score(score); |
jgaltier98 | 0:88b1d5275ad7 | 67 | lcd.DisplayStringAt(XMAX+2, YMIN+2+24+2+24, (uint8_t *)"Best",LEFT_MODE); |
jgaltier98 | 0:88b1d5275ad7 | 68 | while(1) { |
jgaltier98 | 0:88b1d5275ad7 | 69 | |
jgaltier98 | 0:88b1d5275ad7 | 70 | Xaccelerate = i2c_X_axis_read()*10*2; |
jgaltier98 | 0:88b1d5275ad7 | 71 | Yaccelerate = i2c_Y_axis_read()*10*2; |
jgaltier98 | 0:88b1d5275ad7 | 72 | |
jgaltier98 | 0:88b1d5275ad7 | 73 | posX_ship = posX_ship+Xaccelerate; |
jgaltier98 | 0:88b1d5275ad7 | 74 | if(posX_ship<XMIN) posX_ship=XMIN; |
jgaltier98 | 0:88b1d5275ad7 | 75 | if(posX_ship>XMAX-lenght_X_hitbox) posX_ship=XMAX-lenght_X_hitbox-5; |
jgaltier98 | 0:88b1d5275ad7 | 76 | |
jgaltier98 | 0:88b1d5275ad7 | 77 | posY_ship = posY_ship+Yaccelerate; |
jgaltier98 | 0:88b1d5275ad7 | 78 | if(posY_ship<YMIN+height_wing) posY_ship=YMIN+height_wing+5; |
jgaltier98 | 0:88b1d5275ad7 | 79 | if(posY_ship>YMAX-lenght_Y_hitbox+height_wing) posY_ship=YMAX-lenght_Y_hitbox+height_wing; |
jgaltier98 | 0:88b1d5275ad7 | 80 | |
jgaltier98 | 0:88b1d5275ad7 | 81 | posX_line = posX_line-line_speed-speed_difficulty; |
jgaltier98 | 0:88b1d5275ad7 | 82 | if(posX_line<XMIN)posX_line=XMAX; |
jgaltier98 | 0:88b1d5275ad7 | 83 | |
jgaltier98 | 0:88b1d5275ad7 | 84 | posX_line2 = posX_line2-line_speed2-speed_difficulty; |
jgaltier98 | 0:88b1d5275ad7 | 85 | if(posX_line2<XMIN)posX_line2=XMAX; |
jgaltier98 | 0:88b1d5275ad7 | 86 | |
jgaltier98 | 0:88b1d5275ad7 | 87 | posX_line3 = posX_line3-line_speed3-speed_difficulty; |
jgaltier98 | 0:88b1d5275ad7 | 88 | if(posX_line3<XMIN)posX_line3=XMAX; |
jgaltier98 | 0:88b1d5275ad7 | 89 | |
jgaltier98 | 0:88b1d5275ad7 | 90 | |
jgaltier98 | 0:88b1d5275ad7 | 91 | cls_scr(); |
jgaltier98 | 0:88b1d5275ad7 | 92 | for(index_star=0;index_star<10;index_star++){ |
jgaltier98 | 0:88b1d5275ad7 | 93 | draw_star(pos_star[index_star][0],pos_star[index_star][1]); |
jgaltier98 | 0:88b1d5275ad7 | 94 | } |
jgaltier98 | 0:88b1d5275ad7 | 95 | draw_planet(230,100); |
jgaltier98 | 0:88b1d5275ad7 | 96 | draw_planet(100,230); |
jgaltier98 | 0:88b1d5275ad7 | 97 | draw_ship(posX_ship,posY_ship,false,fire_frame); |
jgaltier98 | 0:88b1d5275ad7 | 98 | hit = draw_line(posX_line,YMIN+100,40,posX_ship,posY_ship); |
jgaltier98 | 0:88b1d5275ad7 | 99 | hit2 = draw_line(posX_line3,YMIN,40,posX_ship,posY_ship); |
jgaltier98 | 0:88b1d5275ad7 | 100 | hit3 = draw_line(posX_line,YMAX-40,40,posX_ship,posY_ship); |
jgaltier98 | 0:88b1d5275ad7 | 101 | hit4 = draw_line(posX_line2,YMIN+45,40,posX_ship,posY_ship); |
jgaltier98 | 0:88b1d5275ad7 | 102 | hit5 = draw_line(posX_line3,YMIN+145,40,posX_ship,posY_ship); |
jgaltier98 | 0:88b1d5275ad7 | 103 | score += 1; |
jgaltier98 | 0:88b1d5275ad7 | 104 | if(score>1000 && flag_level_difficulty == 3){ |
jgaltier98 | 0:88b1d5275ad7 | 105 | speed_difficulty+=5; |
jgaltier98 | 0:88b1d5275ad7 | 106 | flag_level_difficulty=4; |
jgaltier98 | 0:88b1d5275ad7 | 107 | } |
jgaltier98 | 0:88b1d5275ad7 | 108 | if(score>750 && flag_level_difficulty == 2){ |
jgaltier98 | 0:88b1d5275ad7 | 109 | speed_difficulty+=2; |
jgaltier98 | 0:88b1d5275ad7 | 110 | flag_level_difficulty=3; |
jgaltier98 | 0:88b1d5275ad7 | 111 | } |
jgaltier98 | 0:88b1d5275ad7 | 112 | if(score>500 && flag_level_difficulty == 1){ |
jgaltier98 | 0:88b1d5275ad7 | 113 | speed_difficulty+=2; |
jgaltier98 | 0:88b1d5275ad7 | 114 | flag_level_difficulty=2; |
jgaltier98 | 0:88b1d5275ad7 | 115 | } |
jgaltier98 | 0:88b1d5275ad7 | 116 | if(score>250 && flag_level_difficulty == 0){ |
jgaltier98 | 0:88b1d5275ad7 | 117 | speed_difficulty+=2; |
jgaltier98 | 0:88b1d5275ad7 | 118 | flag_level_difficulty=1; |
jgaltier98 | 0:88b1d5275ad7 | 119 | } |
jgaltier98 | 0:88b1d5275ad7 | 120 | fire_frame ++; |
jgaltier98 | 0:88b1d5275ad7 | 121 | fire_frame = fire_frame%2; |
jgaltier98 | 0:88b1d5275ad7 | 122 | if(hit == true || hit2 == true || hit3 == true || hit4 == true || hit5 == true ){ |
jgaltier98 | 0:88b1d5275ad7 | 123 | if(score>best){ |
jgaltier98 | 0:88b1d5275ad7 | 124 | best=score; |
jgaltier98 | 0:88b1d5275ad7 | 125 | died(1); |
jgaltier98 | 0:88b1d5275ad7 | 126 | } |
jgaltier98 | 0:88b1d5275ad7 | 127 | else{ |
jgaltier98 | 0:88b1d5275ad7 | 128 | died(0); |
jgaltier98 | 0:88b1d5275ad7 | 129 | } |
jgaltier98 | 0:88b1d5275ad7 | 130 | display_best(best); |
jgaltier98 | 0:88b1d5275ad7 | 131 | score = 0; |
jgaltier98 | 0:88b1d5275ad7 | 132 | posX_ship = 0; |
jgaltier98 | 0:88b1d5275ad7 | 133 | posX_line = XMAX; |
jgaltier98 | 0:88b1d5275ad7 | 134 | posX_line2 = XMAX; |
jgaltier98 | 0:88b1d5275ad7 | 135 | posX_line3 = XMAX; |
jgaltier98 | 0:88b1d5275ad7 | 136 | speed_difficulty=0; |
jgaltier98 | 0:88b1d5275ad7 | 137 | hit = false; |
jgaltier98 | 0:88b1d5275ad7 | 138 | } |
jgaltier98 | 0:88b1d5275ad7 | 139 | display_score(score); |
jgaltier98 | 0:88b1d5275ad7 | 140 | wait(0.05); |
jgaltier98 | 0:88b1d5275ad7 | 141 | } |
jgaltier98 | 0:88b1d5275ad7 | 142 | } |
jgaltier98 | 0:88b1d5275ad7 | 143 | |
jgaltier98 | 0:88b1d5275ad7 | 144 |