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

Files at this revision

API Documentation at this revision

Comitter:
jgaltier98
Date:
Tue Jun 04 12:53:19 2019 +0000
Commit message:
projet interfacage

Changed in this revision

BSP_DISCO_F746NG.lib Show annotated file Show diff for this revision Revisions of this file
LCD_DISCO_F746NG.lib Show annotated file Show diff for this revision Revisions of this file
MMA8451Q.lib Show annotated file Show diff for this revision Revisions of this file
TS_DISCO_F746NG.lib Show annotated file Show diff for this revision Revisions of this file
accelerometre.cpp Show annotated file Show diff for this revision Revisions of this file
accelerometre.h Show annotated file Show diff for this revision Revisions of this file
display.cpp Show annotated file Show diff for this revision Revisions of this file
display.h Show annotated file Show diff for this revision Revisions of this file
draw.cpp Show annotated file Show diff for this revision Revisions of this file
draw.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/BSP_DISCO_F746NG.lib	Tue Jun 04 12:53:19 2019 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/teams/ST/code/BSP_DISCO_F746NG/#df2ea349c37a
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LCD_DISCO_F746NG.lib	Tue Jun 04 12:53:19 2019 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/teams/ST/code/LCD_DISCO_F746NG/#d44525b1de98
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MMA8451Q.lib	Tue Jun 04 12:53:19 2019 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/teams/MSS/code/MMA8451Q/#5a09d01c6a2c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TS_DISCO_F746NG.lib	Tue Jun 04 12:53:19 2019 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/teams/ST/code/TS_DISCO_F746NG/#fe0cf5e2960f
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/accelerometre.cpp	Tue Jun 04 12:53:19 2019 +0000
@@ -0,0 +1,11 @@
+#include "accelerometre.h"
+
+MMA8451Q acc(PB_9, PB_8,MMA8451_I2C_ADDRESS);
+
+float i2c_X_axis_read(void){   
+    return acc.getAccX();
+}
+
+float i2c_Y_axis_read(void){
+    return acc.getAccY();
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/accelerometre.h	Tue Jun 04 12:53:19 2019 +0000
@@ -0,0 +1,7 @@
+#include "mbed.h"
+#include "MMA8451Q.h"
+
+#define MMA8451_I2C_ADDRESS (0x1D<<0)
+
+float i2c_X_axis_read(void);
+float i2c_Y_axis_read(void);
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/display.cpp	Tue Jun 04 12:53:19 2019 +0000
@@ -0,0 +1,34 @@
+#include "display.h"
+
+void display_score(short score){
+    char convert_score[5]={0};
+    sprintf(convert_score,"%hd",score);
+    lcd.SetTextColor(LCD_COLOR_BLACK);
+    lcd.FillRect(XMAX+2,YMIN+2+24,80,24);
+    lcd.SetTextColor(LCD_COLOR_GREEN);
+    lcd.DisplayStringAt(XMAX+2, YMIN+2+24, (uint8_t *)convert_score,LEFT_MODE);  
+}
+void display_best(short best){
+    char convert_best[5]={0};
+    sprintf(convert_best,"%hd",best);
+    lcd.DisplayStringAt(XMAX+2, YMIN+2+24+2+24+2+24, (uint8_t *)convert_best,LEFT_MODE);  
+}
+
+void cls_scr(void){
+    lcd.SetTextColor(LCD_COLOR_BLACK);
+    lcd.FillRect(XMIN,YMIN+1,XMAX,YMAX);
+    lcd.SetTextColor(LCD_COLOR_GREEN);    
+    
+}
+
+void died(short A){
+    lcd.SetTextColor(LCD_COLOR_BLACK);
+    lcd.FillRect(XMIN,YMIN+50,XMAX,100);
+    lcd.SetTextColor(LCD_COLOR_RED); 
+    lcd.DisplayStringAt(XMIN, YMIN+65, (uint8_t *)"FATALITY", CENTER_MODE);
+    wait(2);
+    if(A==0)lcd.DisplayStringAt(XMIN, YMIN+65+24+2, (uint8_t *)"Defeat", CENTER_MODE);  
+    if(A==1)lcd.DisplayStringAt(XMIN, YMIN+65+24+2, (uint8_t *)"You Win", CENTER_MODE);     
+    wait(3); 
+    lcd.SetTextColor(LCD_COLOR_GREEN);     
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/display.h	Tue Jun 04 12:53:19 2019 +0000
@@ -0,0 +1,14 @@
+#include "mbed.h"
+#include "LCD_DISCO_F746NG.h"
+
+#define YMIN 25
+#define YMAX 272
+#define XMIN 0
+#define XMAX 390
+
+extern LCD_DISCO_F746NG lcd;
+
+void display_score(short score);
+void display_best(short best);
+void cls_scr(void);
+void died(short A);
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/draw.cpp	Tue Jun 04 12:53:19 2019 +0000
@@ -0,0 +1,204 @@
+#include "draw.h"
+
+void draw_hitbox_ship(short posX, short posY){
+    lcd.SetTextColor(LCD_COLOR_RED);
+    lcd.DrawRect(posX,posY-height_wing,lenght_X_hitbox,lenght_Y_hitbox);  
+    lcd.SetTextColor(LCD_COLOR_GREEN);  
+}
+
+void draw_star(short X, short Y){
+    char star[5][5]={{1,0,1,0,1},
+                     {0,0,1,0,0},
+                     {1,1,0,1,1},
+                     {0,0,1,0,0},
+                     {1,0,1,0,1}} ;
+    short i,j;  
+    for(i=0;i<5;i++){
+        for(j=0;j<5;j++){
+            if(star[j][i]==0){ 
+                lcd.DrawPixel(X+i,Y+j,LCD_COLOR_BLACK);
+            }
+            else{
+                lcd.DrawPixel(X+i,Y+j,LCD_COLOR_YELLOW);
+            }
+        }
+    }     
+}
+
+void draw_fire(short X,short Y, short fire){
+    char fire1[10][10]={{1,1,0,0,0,1,0,0,0,0}, 
+                        {0,0,1,1,0,0,1,0,0,0},
+                        {0,0,0,0,1,1,2,1,0,0},
+                        {0,0,1,1,2,2,2,2,1,0},
+                        {1,1,2,2,2,2,2,2,2,1},
+                        {1,1,2,2,2,2,2,2,2,1},
+                        {0,0,1,1,2,2,2,2,1,0},
+                        {0,0,0,0,1,1,2,1,0,0},
+                        {0,0,1,1,0,0,1,0,0,0},
+                        {1,1,0,0,0,1,0,0,0,0}}; 
+                         
+    char fire2[10][10]={{0,0,0,0,0,0,0,0,0,0}, 
+                        {0,0,0,0,0,0,0,0,0,0},
+                        {0,0,0,0,0,0,1,1,0,0},
+                        {0,0,0,0,0,1,2,2,1,0},
+                        {0,0,0,0,1,2,2,2,2,1},
+                        {0,0,0,0,1,2,2,2,2,1},
+                        {0,0,0,0,0,1,2,2,1,0},
+                        {0,0,0,0,0,0,1,1,0,0},
+                        {0,0,0,0,0,0,0,0,0,0},
+                        {0,0,0,0,0,0,0,0,0,0}};  
+    short i,j;  
+    X=X-10;
+    
+    for(i=0;i<10;i++){
+        for(j=0;j<10;j++){
+            if(fire == 0){
+                if(fire1[j][i]==0){ 
+                    lcd.DrawPixel(X+i,Y+j,LCD_COLOR_BLACK);
+                }
+                else if(fire1[j][i]==1){
+                    lcd.DrawPixel(X+i,Y+j,LCD_COLOR_YELLOW);
+                }
+                else if(fire1[j][i]==2){
+                    lcd.DrawPixel(X+i,Y+j,LCD_COLOR_RED);
+                }
+            }
+            else{
+                if(fire2[j][i]==0){ 
+                    lcd.DrawPixel(X+i,Y+j,LCD_COLOR_BLACK);
+                }
+                else if(fire2[j][i]==1){
+                    lcd.DrawPixel(X+i,Y+j,LCD_COLOR_YELLOW);
+                }
+                else if(fire2[j][i]==2){
+                    lcd.DrawPixel(X+i,Y+j,LCD_COLOR_RED);
+                }                
+            }
+        }
+    } 
+}
+
+void draw_planet(short X,short Y){
+    char planet[14][20]={
+        {0,0,0,0,0,0,0,0,0,3,3,0,0,0,0,0,0,0,0,0},
+        {0,0,0,0,0,0,0,3,3,3,3,3,3,0,0,0,0,0,0,0},
+        {0,0,0,0,0,0,3,4,4,4,3,4,4,3,0,0,0,0,0,0},
+        {0,0,5,5,5,3,3,3,4,4,3,3,4,4,3,0,0,0,0,0},
+        {5,5,5,5,3,4,4,3,3,4,4,3,3,4,4,3,5,5,0,0},
+        {5,5,0,0,3,4,4,4,3,3,3,4,3,3,4,3,5,5,5,5},
+        {5,5,0,3,3,4,4,4,4,3,3,3,4,3,3,3,3,0,5,5},
+        {0,5,5,3,3,4,4,4,4,4,4,3,3,4,4,3,3,5,5,0},
+        {0,5,5,5,3,4,4,4,4,4,4,4,3,3,3,5,5,5,0,0},
+        {0,0,5,5,5,5,5,4,4,4,4,4,5,5,5,5,5,0,0,0},
+        {0,0,0,0,5,5,5,5,5,5,5,5,5,5,5,0,0,0,0,0},
+        {0,0,0,0,0,0,3,5,5,5,5,5,4,3,0,0,0,0,0,0},
+        {0,0,0,0,0,0,0,3,3,3,3,3,3,0,0,0,0,0,0,0},//
+        {0,0,0,0,0,0,0,0,0,3,3,0,0,0,0,0,0,0,0,0}
+        };    
+    short i,j;  
+    
+    for(i=0;i<20;i++){
+        for(j=0;j<14;j++){
+            if(planet[j][i]==0){ 
+                lcd.DrawPixel(X+i,Y+j,LCD_COLOR_BLACK);
+            }
+            else if (planet[j][i]==3){
+                lcd.DrawPixel(X+i,Y+j,LCD_COLOR_MAGENTA);
+            }
+            else if (planet[j][i]==4){
+                lcd.DrawPixel(X+i,Y+j,LCD_COLOR_CYAN);
+            }
+            else if (planet[j][i]==5){
+                lcd.DrawPixel(X+i,Y+j,LCD_COLOR_ORANGE);
+            }
+        }
+    } 
+}
+
+void draw_load(short X, short Y){   
+    short i,j,progress;
+    char convert_progress[5]={0};
+    Y=Y+4;
+    
+    for(progress=0;progress<100;progress++){
+        for(i=0;i<progress;i++){
+            for(j=0;j<10;j++){
+                lcd.DrawPixel(X+i,Y+j,LCD_COLOR_GREEN);
+            }
+        } 
+        sprintf(convert_progress,"%hd%%",progress);
+        lcd.DisplayStringAt(300, LINE(7), (uint8_t *)convert_progress,LEFT_MODE);  
+        wait(0.1);
+    }      
+}
+
+void draw_hit(short X,short Y){
+    char explosion[10][10]={
+        {2,0,0,0,1,1,0,0,0,2},    
+        {0,2,2,0,1,1,0,2,2,0}, 
+        {0,2,0,2,1,1,2,0,2,0}, 
+        {0,0,2,2,1,1,2,2,0,0}, 
+        {1,1,1,1,2,2,1,1,1,1}, 
+        {1,1,1,1,2,2,1,1,1,1},    
+        {0,0,2,2,1,1,2,2,0,0}, 
+        {0,2,0,2,1,1,2,0,2,0}, 
+        {0,2,2,0,1,1,0,2,2,0}, 
+        {2,0,0,0,1,1,0,0,0,2}};
+    short i,j; 
+     
+    for(i=0;i<10;i++){
+        for(j=0;j<10;j++){
+            if(explosion[j][i]==0){ 
+                lcd.DrawPixel(X+i,Y+j,LCD_COLOR_BLACK);
+            }
+            else if (explosion[j][i]==1){
+                lcd.DrawPixel(X+i,Y+j,LCD_COLOR_YELLOW);
+            }
+            else if (explosion[j][i]==2){
+                lcd.DrawPixel(X+i,Y+j,LCD_COLOR_RED);
+            }
+        }
+    }    
+} 
+
+void draw_ship(short posX, short posY, bool hitbox, short fire){   
+    //body
+    lcd.DrawRect(posX,posY,bodyX,bodyY); 
+    //nose
+    lcd.DrawLine(posX+bodyX,posY,posX+bodyX+lenght_nose,posY+height_nose );   
+    lcd.DrawLine(posX+bodyX,posY+bodyY,posX+bodyX+lenght_nose,posY+height_nose );  
+    //up wing
+    lcd.DrawLine(posX,posY,posX,posY-height_wing);   
+    lcd.DrawLine(posX+lenght_wing,posY,posX,posY-height_wing);
+    //down wing
+    lcd.DrawLine(posX,posY+bodyY,posX,posY+bodyY+height_wing);   
+    lcd.DrawLine(posX+lenght_wing,posY+bodyY,posX,posY+bodyY+height_wing);
+    
+    draw_fire(posX,posY,fire);
+    //hitbox
+    if (hitbox){
+        draw_hitbox_ship(posX,posY);    
+    } 
+}
+bool draw_line(short posX, short posY, short lenght,short posX_ship, short posY_ship){
+    short coord_slide_line;
+    bool hit = false;
+    bool flag_hit = false;
+    
+    posY_ship = posY_ship - height_wing;
+    lcd.DrawLine(posX,posY,posX,posY+lenght); 
+    
+    if(posX>posX_ship and posX<posX_ship+lenght_X_hitbox){
+        for(coord_slide_line=posY;coord_slide_line<=posY+lenght;coord_slide_line++){
+            
+            if(coord_slide_line>posY_ship and coord_slide_line<posY_ship+lenght_Y_hitbox){    
+                hit = true; 
+                if(flag_hit == false){
+                    draw_hit(posX,coord_slide_line);
+                    flag_hit = true;
+                }
+            }  
+        }
+    }
+    return hit;      
+}    
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/draw.h	Tue Jun 04 12:53:19 2019 +0000
@@ -0,0 +1,22 @@
+#include "mbed.h"
+#include "LCD_DISCO_F746NG.h"
+
+#define bodyX 20
+#define bodyY 10
+#define lenght_nose 15
+#define height_nose 5
+#define height_wing 8
+#define lenght_wing 15
+
+extern LCD_DISCO_F746NG lcd;
+extern short lenght_X_hitbox;
+extern short lenght_Y_hitbox;
+
+void draw_hitbox_ship(short lenght_X, short lenght_Y);
+void draw_star(short X, short Y);
+void draw_fire(short X,short Y,short fire);
+void draw_planet(short X, short Y);
+void draw_load(short X, short Y);
+void draw_hit(short X,short Y);
+void draw_ship(short posX,short posY, bool hitbox, short fire);
+bool draw_line(short posX, short posY, short lenght,short posX_ship, short posY_ship);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Jun 04 12:53:19 2019 +0000
@@ -0,0 +1,144 @@
+#include "mbed.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include "LCD_DISCO_F746NG.h"
+#include "fonts.h"
+#include "TS_DISCO_F746NG.h"
+
+#include "draw.h"
+#include "display.h"
+#include "accelerometre.h"
+
+#define line_speed  2
+#define line_speed2 4
+#define line_speed3 6
+
+LCD_DISCO_F746NG lcd;
+TS_DISCO_F746NG ts;
+short lenght_X_hitbox = bodyX + lenght_nose;
+short lenght_Y_hitbox = bodyY + 2*height_wing;
+
+
+
+int main()
+{
+    TS_StateTypeDef TS_State;
+    
+    bool hit = false;
+    bool hit2 = false;
+    bool hit3 = false;
+    bool hit4 = false;
+    bool hit5 = false;
+    short fire_frame=0;
+    
+    short int score = 0,best = 0;
+    
+    short posX_line = 0;
+    short posX_line2 = 0;
+    short posX_line3 = 0;
+    short posX_ship = 0;
+    short posY_ship = 0;
+    short index_star = 0;
+    short Xaccelerate=0;
+    short Yaccelerate=0;
+    short speed_difficulty=0,flag_level_difficulty=0;
+    
+    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}};
+    uint8_t status;
+    bool continuer=true;
+    status = ts.Init(lcd.GetXSize(), lcd.GetYSize());
+    lcd.SetBackColor(LCD_COLOR_BLACK);
+    lcd.SetTextColor(LCD_COLOR_GREEN);
+    lcd.Clear(LCD_COLOR_BLACK);
+    lcd.DisplayStringAt(0, LINE(1), (uint8_t *)"welcome to", CENTER_MODE);
+    lcd.DisplayStringAt(0, LINE(2), (uint8_t *)"ESCAPE THE LINE", CENTER_MODE);
+    draw_load(190, LINE(7));
+    lcd.DisplayStringAt(0, LINE(8), (uint8_t *)"Touch to start!", CENTER_MODE);
+    while(continuer){
+        ts.GetState(&TS_State);
+        if(TS_State.touchDetected)continuer=false;
+    }
+    
+    lcd.DisplayStringAt(0, LINE(0), (uint8_t *)"Escape the line v1.0", LEFT_MODE); 
+    lcd.DrawHLine(0,YMIN,480);  
+    lcd.DrawVLine(XMAX,YMIN,YMAX-YMIN);
+    lcd.DisplayStringAt(XMAX+2, YMIN+2, (uint8_t *)"Score",LEFT_MODE); 
+    display_score(score);
+    lcd.DisplayStringAt(XMAX+2, YMIN+2+24+2+24, (uint8_t *)"Best",LEFT_MODE); 
+    while(1) {
+        
+            Xaccelerate = i2c_X_axis_read()*10*2;
+            Yaccelerate = i2c_Y_axis_read()*10*2;
+            
+            posX_ship = posX_ship+Xaccelerate;            
+            if(posX_ship<XMIN) posX_ship=XMIN;
+            if(posX_ship>XMAX-lenght_X_hitbox) posX_ship=XMAX-lenght_X_hitbox-5;
+            
+            posY_ship = posY_ship+Yaccelerate;            
+            if(posY_ship<YMIN+height_wing) posY_ship=YMIN+height_wing+5;
+            if(posY_ship>YMAX-lenght_Y_hitbox+height_wing) posY_ship=YMAX-lenght_Y_hitbox+height_wing;
+            
+            posX_line = posX_line-line_speed-speed_difficulty;
+            if(posX_line<XMIN)posX_line=XMAX;
+            
+            posX_line2 = posX_line2-line_speed2-speed_difficulty;
+            if(posX_line2<XMIN)posX_line2=XMAX;
+            
+            posX_line3 = posX_line3-line_speed3-speed_difficulty;
+            if(posX_line3<XMIN)posX_line3=XMAX;
+            
+             
+            cls_scr();
+            for(index_star=0;index_star<10;index_star++){
+                draw_star(pos_star[index_star][0],pos_star[index_star][1]);    
+            }
+            draw_planet(230,100);
+            draw_planet(100,230);
+            draw_ship(posX_ship,posY_ship,false,fire_frame);
+            hit = draw_line(posX_line,YMIN+100,40,posX_ship,posY_ship);
+            hit2 = draw_line(posX_line3,YMIN,40,posX_ship,posY_ship);
+            hit3 = draw_line(posX_line,YMAX-40,40,posX_ship,posY_ship);
+            hit4 = draw_line(posX_line2,YMIN+45,40,posX_ship,posY_ship);
+            hit5 = draw_line(posX_line3,YMIN+145,40,posX_ship,posY_ship);
+            score += 1;
+            if(score>1000 && flag_level_difficulty == 3){
+                speed_difficulty+=5;
+                flag_level_difficulty=4;
+            }
+            if(score>750 && flag_level_difficulty == 2){
+                speed_difficulty+=2;
+                flag_level_difficulty=3;
+            }
+            if(score>500 && flag_level_difficulty == 1){
+                speed_difficulty+=2;
+                flag_level_difficulty=2;
+            }
+            if(score>250 && flag_level_difficulty == 0){
+                speed_difficulty+=2;
+                flag_level_difficulty=1;
+            }
+            fire_frame ++;
+            fire_frame = fire_frame%2;
+            if(hit == true || hit2 == true || hit3 == true || hit4 == true || hit5 == true ){
+                if(score>best){
+                    best=score;
+                    died(1);
+                }
+                else{
+                    died(0);
+                }
+                display_best(best);
+                score = 0;
+                posX_ship = 0;
+                posX_line = XMAX;
+                posX_line2 = XMAX;
+                posX_line3 = XMAX;
+                speed_difficulty=0;
+                hit = false;
+            }
+            display_score(score);
+            wait(0.05);       
+    }
+}
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Tue Jun 04 12:53:19 2019 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/3a7713b1edbc
\ No newline at end of file