You will be able to control a yellow ball through a level like a labyrinth
Dependencies: BSP_DISCO_F746NG LCD_DISCO_F746NG MMA7660FC TS_DISCO_F746NG mbed
main.cpp@0:9167afeead2e, 2018-05-29 (annotated)
- Committer:
- IUT_Nicolas_C
- Date:
- Tue May 29 14:42:38 2018 +0000
- Revision:
- 0:9167afeead2e
- Child:
- 1:f41e3d62e7b2
coucou, ?a marche, bisous; ; sauvegarde
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
IUT_Nicolas_C | 0:9167afeead2e | 1 | #include "mbed.h" |
IUT_Nicolas_C | 0:9167afeead2e | 2 | #include "LCD_DISCO_F746NG.h" |
IUT_Nicolas_C | 0:9167afeead2e | 3 | #include <MMA7660FC.h> |
IUT_Nicolas_C | 0:9167afeead2e | 4 | |
IUT_Nicolas_C | 0:9167afeead2e | 5 | #define SLAVE_ADRESS 0x4c |
IUT_Nicolas_C | 0:9167afeead2e | 6 | |
IUT_Nicolas_C | 0:9167afeead2e | 7 | //---PIN SETUP |
IUT_Nicolas_C | 0:9167afeead2e | 8 | MMA7660FC sensor(PB_9,PB_8,SLAVE_ADRESS<<1); |
IUT_Nicolas_C | 0:9167afeead2e | 9 | LCD_DISCO_F746NG lcd; |
IUT_Nicolas_C | 0:9167afeead2e | 10 | DigitalOut myled(LED1); |
IUT_Nicolas_C | 0:9167afeead2e | 11 | |
IUT_Nicolas_C | 0:9167afeead2e | 12 | //---DECLARATION |
IUT_Nicolas_C | 0:9167afeead2e | 13 | void initLCD(); |
IUT_Nicolas_C | 0:9167afeead2e | 14 | void displayAcc(float,float,float); |
IUT_Nicolas_C | 0:9167afeead2e | 15 | void displayPos(int,int,int); |
IUT_Nicolas_C | 0:9167afeead2e | 16 | void displayOrientation(const char*); |
IUT_Nicolas_C | 0:9167afeead2e | 17 | void drawRect(int,int,int,int); |
IUT_Nicolas_C | 0:9167afeead2e | 18 | void drawUi(); |
IUT_Nicolas_C | 0:9167afeead2e | 19 | void drawUiButtons(); |
IUT_Nicolas_C | 0:9167afeead2e | 20 | void drawUiStructure(); |
IUT_Nicolas_C | 0:9167afeead2e | 21 | |
IUT_Nicolas_C | 0:9167afeead2e | 22 | //---INITIALISATION |
IUT_Nicolas_C | 0:9167afeead2e | 23 | void initLCD() { |
IUT_Nicolas_C | 0:9167afeead2e | 24 | lcd.Clear(LCD_COLOR_WHITE); |
IUT_Nicolas_C | 0:9167afeead2e | 25 | lcd.SetBackColor(LCD_COLOR_BLUE); |
IUT_Nicolas_C | 0:9167afeead2e | 26 | lcd.SetTextColor(LCD_COLOR_BLACK); |
IUT_Nicolas_C | 0:9167afeead2e | 27 | wait(0.3); |
IUT_Nicolas_C | 0:9167afeead2e | 28 | } |
IUT_Nicolas_C | 0:9167afeead2e | 29 | void displayAcc(float x, float y, float z) { |
IUT_Nicolas_C | 0:9167afeead2e | 30 | char string[50]; |
IUT_Nicolas_C | 0:9167afeead2e | 31 | sprintf(string,"AX = %3.3f",x); |
IUT_Nicolas_C | 0:9167afeead2e | 32 | lcd.DisplayStringAt(0, LINE(5), (uint8_t *)string, CENTER_MODE); |
IUT_Nicolas_C | 0:9167afeead2e | 33 | sprintf(string,"AY = %3.3f",y); |
IUT_Nicolas_C | 0:9167afeead2e | 34 | lcd.DisplayStringAt(0, LINE(6), (uint8_t *)string, CENTER_MODE); |
IUT_Nicolas_C | 0:9167afeead2e | 35 | sprintf(string,"AZ = %3.3f",z); |
IUT_Nicolas_C | 0:9167afeead2e | 36 | lcd.DisplayStringAt(0, LINE(7), (uint8_t *)string, CENTER_MODE); |
IUT_Nicolas_C | 0:9167afeead2e | 37 | } |
IUT_Nicolas_C | 0:9167afeead2e | 38 | void displayOrientation(const char *o) { |
IUT_Nicolas_C | 0:9167afeead2e | 39 | char string[50]; |
IUT_Nicolas_C | 0:9167afeead2e | 40 | sprintf(string,"O = %s",o); |
IUT_Nicolas_C | 0:9167afeead2e | 41 | lcd.DisplayStringAt(0, LINE(4), (uint8_t *)string, CENTER_MODE); |
IUT_Nicolas_C | 0:9167afeead2e | 42 | |
IUT_Nicolas_C | 0:9167afeead2e | 43 | } |
IUT_Nicolas_C | 0:9167afeead2e | 44 | void displayPos(int x, int y, int z) { |
IUT_Nicolas_C | 0:9167afeead2e | 45 | char string[50]; |
IUT_Nicolas_C | 0:9167afeead2e | 46 | sprintf(string,"X = %03d",x); |
IUT_Nicolas_C | 0:9167afeead2e | 47 | lcd.DisplayStringAt(0, LINE(1), (uint8_t *)string, CENTER_MODE); |
IUT_Nicolas_C | 0:9167afeead2e | 48 | sprintf(string,"Y = %03d",y); |
IUT_Nicolas_C | 0:9167afeead2e | 49 | lcd.DisplayStringAt(0, LINE(2), (uint8_t *)string, CENTER_MODE); |
IUT_Nicolas_C | 0:9167afeead2e | 50 | sprintf(string,"Z = %03d",z); |
IUT_Nicolas_C | 0:9167afeead2e | 51 | lcd.DisplayStringAt(0, LINE(3), (uint8_t *)string, CENTER_MODE); |
IUT_Nicolas_C | 0:9167afeead2e | 52 | } |
IUT_Nicolas_C | 0:9167afeead2e | 53 | void drawRect(int x1, int y1, int x2, int y2) { |
IUT_Nicolas_C | 0:9167afeead2e | 54 | lcd.DrawRect(x1, y1, x2-x1, y2-y1); |
IUT_Nicolas_C | 0:9167afeead2e | 55 | } |
IUT_Nicolas_C | 0:9167afeead2e | 56 | void drawUi() { |
IUT_Nicolas_C | 0:9167afeead2e | 57 | drawUiStructure(); |
IUT_Nicolas_C | 0:9167afeead2e | 58 | drawUiButtons(); |
IUT_Nicolas_C | 0:9167afeead2e | 59 | } |
IUT_Nicolas_C | 0:9167afeead2e | 60 | void drawUiButtons() { |
IUT_Nicolas_C | 0:9167afeead2e | 61 | lcd.SetTextColor(LCD_COLOR_BLUE); |
IUT_Nicolas_C | 0:9167afeead2e | 62 | drawRect(415, 15,465, 65); |
IUT_Nicolas_C | 0:9167afeead2e | 63 | drawRect(415,207,465,257); |
IUT_Nicolas_C | 0:9167afeead2e | 64 | } |
IUT_Nicolas_C | 0:9167afeead2e | 65 | void drawUiStructure() { |
IUT_Nicolas_C | 0:9167afeead2e | 66 | lcd.SetTextColor(LCD_COLOR_BLACK); |
IUT_Nicolas_C | 0:9167afeead2e | 67 | drawRect( 10, 10,400,262); |
IUT_Nicolas_C | 0:9167afeead2e | 68 | drawRect(410, 10,470,262); |
IUT_Nicolas_C | 0:9167afeead2e | 69 | } |
IUT_Nicolas_C | 0:9167afeead2e | 70 | |
IUT_Nicolas_C | 0:9167afeead2e | 71 | //---MAIN |
IUT_Nicolas_C | 0:9167afeead2e | 72 | int main() { |
IUT_Nicolas_C | 0:9167afeead2e | 73 | int data[3] = {0,0,0}; |
IUT_Nicolas_C | 0:9167afeead2e | 74 | float ax=0,ay=0,az=0; |
IUT_Nicolas_C | 0:9167afeead2e | 75 | const char *orientation; |
IUT_Nicolas_C | 0:9167afeead2e | 76 | sensor.init(); |
IUT_Nicolas_C | 0:9167afeead2e | 77 | initLCD(); |
IUT_Nicolas_C | 0:9167afeead2e | 78 | drawUi(); |
IUT_Nicolas_C | 0:9167afeead2e | 79 | |
IUT_Nicolas_C | 0:9167afeead2e | 80 | sensor.write_reg(0x07,0); |
IUT_Nicolas_C | 0:9167afeead2e | 81 | sensor.write_reg(0x04,0x000); |
IUT_Nicolas_C | 0:9167afeead2e | 82 | sensor.write_reg(0x07,1); |
IUT_Nicolas_C | 0:9167afeead2e | 83 | |
IUT_Nicolas_C | 0:9167afeead2e | 84 | while(1) { |
IUT_Nicolas_C | 0:9167afeead2e | 85 | //Getting Values |
IUT_Nicolas_C | 0:9167afeead2e | 86 | data[0]=sensor.read_x(); |
IUT_Nicolas_C | 0:9167afeead2e | 87 | data[1]=sensor.read_y(); |
IUT_Nicolas_C | 0:9167afeead2e | 88 | data[2]=sensor.read_z(); |
IUT_Nicolas_C | 0:9167afeead2e | 89 | sensor.read_Tilt(&ax,&ay,&az); |
IUT_Nicolas_C | 0:9167afeead2e | 90 | orientation=sensor.read_Orientation(); |
IUT_Nicolas_C | 0:9167afeead2e | 91 | |
IUT_Nicolas_C | 0:9167afeead2e | 92 | //Printing Values |
IUT_Nicolas_C | 0:9167afeead2e | 93 | lcd.SetTextColor(LCD_COLOR_BLACK); |
IUT_Nicolas_C | 0:9167afeead2e | 94 | displayPos(data[0],data[1],data[2]); |
IUT_Nicolas_C | 0:9167afeead2e | 95 | displayAcc(ax,ay,az); |
IUT_Nicolas_C | 0:9167afeead2e | 96 | displayOrientation(orientation); |
IUT_Nicolas_C | 0:9167afeead2e | 97 | } |
IUT_Nicolas_C | 0:9167afeead2e | 98 | } |