Smart Home Controller

Dependencies:   TS_DISCO_F746NG mbed LCD_DISCO_F746NG BSP_DISCO_F746NG sMotor

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "TS_DISCO_F746NG.h"
00003 #include "LCD_DISCO_F746NG.h"
00004 #include "sMotor.h"
00005 #include "Draw.h"
00006 
00007 // Devices
00008 LCD_DISCO_F746NG lcd;
00009 TS_DISCO_F746NG ts;
00010 sMotor motor(A0, A1, A2, A3);
00011 int step_speed = 2200;
00012 int numstep = 1;
00013 DigitalOut led(D8);
00014 Draw draw;
00015 
00016 int main()
00017 {
00018     // Variables
00019     TS_StateTypeDef TS_State;
00020     uint16_t x, y;
00021     uint8_t text[30];
00022     uint8_t status;
00023     uint8_t idx;
00024     uint8_t touches = 0;
00025     bool touched;
00026     
00027     //Initial conf
00028     status = ts.Init(lcd.GetXSize(), lcd.GetYSize());
00029     lcd.Clear(LCD_COLOR_RED);
00030     lcd.SetBackColor(LCD_COLOR_RED);
00031     lcd.SetTextColor(LCD_COLOR_BLUE);
00032     lcd.SetFont(&Font24);
00033     
00034     //Start screen
00035     lcd.DisplayStringAt(0, LINE(5), (uint8_t *)"Smart Home Controller", CENTER_MODE);
00036     wait(2);
00037     lcd.Clear(LCD_COLOR_RED);
00038     
00039     while(1) {
00040         // Drawing GUI
00041         x = TS_State.touchX[idx];
00042         y = TS_State.touchY[idx];
00043         sprintf((char*)text, "Touch %d: x=%d y=%d    ", touches, x, y);
00044         lcd.DisplayStringAt(0, LINE(0), (uint8_t *)&text, LEFT_MODE);
00045         ts.GetState(&TS_State);
00046         lcd.FillRect(0, 192, 80, 80);
00047         lcd.FillRect(133, 192, 80, 80);
00048         lcd.FillRect(266, 192, 80, 80);
00049         lcd.FillRect(399, 192, 80, 80);
00050         
00051         if ((TS_State.touchDetected == 0) && (touched == true)){
00052             touches++;
00053             touched = false;
00054         }
00055         if (TS_State.touchDetected == 1){
00056             touched = true;
00057         }
00058         
00059         // Button 1
00060         if ((TS_State.touchDetected) && (TS_State.touchX[0] < 100) && (TS_State.touchY[0] > 190 )){
00061             led = 1;
00062         }
00063         else{
00064             led = 0;
00065         }
00066         
00067         // Button 2
00068         if ((TS_State.touchDetected) && (TS_State.touchX[0] > 130) && (TS_State.touchX[0] < 210) && (TS_State.touchY[0] > 190 )){
00069             motor.step(numstep,0,step_speed);            
00070         }
00071         
00072         // Button 3
00073         if ((TS_State.touchDetected) && (TS_State.touchX[0] > 240) && (TS_State.touchX[0] < 320) && (TS_State.touchY[0] > 190 ))
00074         {
00075             lcd.Clear(LCD_COLOR_RED);
00076             lcd.DrawBitmap(0, 0, (uint8_t *)draw.GetStarWars());
00077             wait(5);
00078         }
00079         
00080         // Button 4
00081         if ((TS_State.touchDetected) && (TS_State.touchX[0] > 350) && (TS_State.touchX[0] < 430) && (TS_State.touchY[0] > 190 ))
00082         {
00083             
00084         }
00085     }
00086 }