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
Diff: main.cpp
- Revision:
- 0:9167afeead2e
- Child:
- 1:f41e3d62e7b2
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue May 29 14:42:38 2018 +0000 @@ -0,0 +1,98 @@ +#include "mbed.h" +#include "LCD_DISCO_F746NG.h" +#include <MMA7660FC.h> + +#define SLAVE_ADRESS 0x4c + +//---PIN SETUP +MMA7660FC sensor(PB_9,PB_8,SLAVE_ADRESS<<1); +LCD_DISCO_F746NG lcd; +DigitalOut myled(LED1); + +//---DECLARATION +void initLCD(); +void displayAcc(float,float,float); +void displayPos(int,int,int); +void displayOrientation(const char*); +void drawRect(int,int,int,int); +void drawUi(); +void drawUiButtons(); +void drawUiStructure(); + +//---INITIALISATION +void initLCD() { + lcd.Clear(LCD_COLOR_WHITE); + lcd.SetBackColor(LCD_COLOR_BLUE); + lcd.SetTextColor(LCD_COLOR_BLACK); + wait(0.3); +} +void displayAcc(float x, float y, float z) { + char string[50]; + sprintf(string,"AX = %3.3f",x); + lcd.DisplayStringAt(0, LINE(5), (uint8_t *)string, CENTER_MODE); + sprintf(string,"AY = %3.3f",y); + lcd.DisplayStringAt(0, LINE(6), (uint8_t *)string, CENTER_MODE); + sprintf(string,"AZ = %3.3f",z); + lcd.DisplayStringAt(0, LINE(7), (uint8_t *)string, CENTER_MODE); +} +void displayOrientation(const char *o) { + char string[50]; + sprintf(string,"O = %s",o); + lcd.DisplayStringAt(0, LINE(4), (uint8_t *)string, CENTER_MODE); + +} +void displayPos(int x, int y, int z) { + char string[50]; + sprintf(string,"X = %03d",x); + lcd.DisplayStringAt(0, LINE(1), (uint8_t *)string, CENTER_MODE); + sprintf(string,"Y = %03d",y); + lcd.DisplayStringAt(0, LINE(2), (uint8_t *)string, CENTER_MODE); + sprintf(string,"Z = %03d",z); + lcd.DisplayStringAt(0, LINE(3), (uint8_t *)string, CENTER_MODE); +} +void drawRect(int x1, int y1, int x2, int y2) { + lcd.DrawRect(x1, y1, x2-x1, y2-y1); +} +void drawUi() { + drawUiStructure(); + drawUiButtons(); +} +void drawUiButtons() { + lcd.SetTextColor(LCD_COLOR_BLUE); + drawRect(415, 15,465, 65); + drawRect(415,207,465,257); +} +void drawUiStructure() { + lcd.SetTextColor(LCD_COLOR_BLACK); + drawRect( 10, 10,400,262); + drawRect(410, 10,470,262); +} + +//---MAIN +int main() { + int data[3] = {0,0,0}; + float ax=0,ay=0,az=0; + const char *orientation; + sensor.init(); + initLCD(); + drawUi(); + + sensor.write_reg(0x07,0); + sensor.write_reg(0x04,0x000); + sensor.write_reg(0x07,1); + + while(1) { + //Getting Values + data[0]=sensor.read_x(); + data[1]=sensor.read_y(); + data[2]=sensor.read_z(); + sensor.read_Tilt(&ax,&ay,&az); + orientation=sensor.read_Orientation(); + + //Printing Values + lcd.SetTextColor(LCD_COLOR_BLACK); + displayPos(data[0],data[1],data[2]); + displayAcc(ax,ay,az); + displayOrientation(orientation); + } +}