Nikolaj Mørup / Mbed 2 deprecated GUI_Project

Dependencies:   TS_DISCO_F746NG mbed LCD_DISCO_F746NG BSP_DISCO_F746NG sMotor

Revision:
2:2f4e4558277c
Parent:
1:7f6f6627aacd
Child:
3:ffdd4d778110
--- a/main.cpp	Tue Jan 08 13:36:48 2019 +0000
+++ b/main.cpp	Wed Jan 09 09:15:41 2019 +0000
@@ -2,9 +2,14 @@
 #include "stdio.h"
 #include "TS_DISCO_F746NG.h"
 #include "LCD_DISCO_F746NG.h"
+#include "sMotor.h"
 
+// Devices
 LCD_DISCO_F746NG lcd;
 TS_DISCO_F746NG ts;
+sMotor motor(A0, A1, A2, A3);
+int step_speed = 2200;
+int numstep = 1;
 DigitalOut led(D8);
 
 int main()
@@ -12,9 +17,8 @@
     // Variables
     TS_StateTypeDef TS_State;
     uint16_t x, y;
-    uint16_t status;
     uint8_t text[30];
-    uint8_t text2[30];
+    uint8_t status;
     uint8_t idx;
     uint8_t touches = 0;
     bool touched;
@@ -23,43 +27,57 @@
     status = ts.Init(lcd.GetXSize(), lcd.GetYSize());
     lcd.Clear(LCD_COLOR_RED);
     lcd.SetBackColor(LCD_COLOR_RED);
-    lcd.SetTextColor(LCD_COLOR_WHITE);
+    lcd.SetTextColor(LCD_COLOR_BLUE);
     lcd.SetFont(&Font24);
     
     //Start screen
-    lcd.DisplayStringAt(0, LINE(5), (uint8_t *)"Test String", CENTER_MODE);
+    lcd.DisplayStringAt(0, LINE(5), (uint8_t *)"Smart Home Controller", CENTER_MODE);
     wait(2);
     lcd.Clear(LCD_COLOR_RED);
     
     while(1) {
+        // Drawing GUI
         x = TS_State.touchX[idx];
         y = TS_State.touchY[idx];
         sprintf((char*)text, "Touch %d: x=%d y=%d    ", touches, x, y);
         lcd.DisplayStringAt(0, LINE(0), (uint8_t *)&text, LEFT_MODE);
         ts.GetState(&TS_State);
-        lcd.DrawRect(0, 190, 80, 80);
-        lcd.DrawRect(133, 190, 80, 80);
-        lcd.DrawRect(266, 190, 80, 80);
-        lcd.DrawRect(399, 190, 80, 80);
+        lcd.FillRect(0, 192, 80, 80);
+        lcd.FillRect(133, 192, 80, 80);
+        lcd.FillRect(266, 192, 80, 80);
+        lcd.FillRect(399, 192, 80, 80);
         
-        if ((TS_State.touchDetected == 0) && (touched == true))
-        {
+        if ((TS_State.touchDetected == 0) && (touched == true)){
             touches++;
             touched = false;
-
         }
-        if (TS_State.touchDetected == 1)
-        {
+        if (TS_State.touchDetected == 1){
             touched = true;
         }
-
-        if ((TS_State.touchDetected) && (TS_State.touchX[0] < 100) && (TS_State.touchY[0] > 190 ))
-        {
+        
+        // Button 1
+        if ((TS_State.touchDetected) && (TS_State.touchX[0] < 100) && (TS_State.touchY[0] > 190 )){
             led = 1;
         }
-        else
+        else{
+            led = 0;
+        }
+        
+        // Button 2
+        if ((TS_State.touchDetected) && (TS_State.touchX[0] > 130) && (TS_State.touchX[0] < 210) && (TS_State.touchY[0] > 190 )){
+            motor.step(numstep,0,step_speed);            
+        }
+        
+        // Button 3
+        if ((TS_State.touchDetected) && (TS_State.touchX[0] > 240) && (TS_State.touchX[0] < 320) && (TS_State.touchY[0] > 190 ))
         {
-            led = 0;
+            
+        }
+        
+        // Button 4
+        if ((TS_State.touchDetected) && (TS_State.touchX[0] > 350) && (TS_State.touchX[0] < 430) && (TS_State.touchY[0] > 190 ))
+        {
+            
         }
     }
 }