exemplo de acender led utilizando toque na tela e botão

Dependencies:   BSP_DISCO_F746NG LCD_DISCO_F746NG TS_DISCO_F746NG mbed

Files at this revision

API Documentation at this revision

Comitter:
felipinhom
Date:
Thu Sep 06 21:27:41 2018 +0000
Commit message:
primeiro programa: ativar led por bot?o e toque

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
TS_DISCO_F746NG.lib 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
diff -r 000000000000 -r c6d1896596c0 BSP_DISCO_F746NG.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/BSP_DISCO_F746NG.lib	Thu Sep 06 21:27:41 2018 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/teams/ST/code/BSP_DISCO_F746NG/#df2ea349c37a
diff -r 000000000000 -r c6d1896596c0 LCD_DISCO_F746NG.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LCD_DISCO_F746NG.lib	Thu Sep 06 21:27:41 2018 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/teams/ST/code/LCD_DISCO_F746NG/#d44525b1de98
diff -r 000000000000 -r c6d1896596c0 TS_DISCO_F746NG.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TS_DISCO_F746NG.lib	Thu Sep 06 21:27:41 2018 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/teams/ST/code/TS_DISCO_F746NG/#fe0cf5e2960f
diff -r 000000000000 -r c6d1896596c0 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Sep 06 21:27:41 2018 +0000
@@ -0,0 +1,81 @@
+#include "mbed.h"
+#include "TS_DISCO_F746NG.h"
+#include "LCD_DISCO_F746NG.h"
+
+//configura pino de interrupção para utilizar no botão da placa (botão azul)
+InterruptIn button(USER_BUTTON);
+
+//configura um pino de saida (no caso o D0)
+DigitalOut led(D0);
+
+LCD_DISCO_F746NG lcd; //objetod e controle do display lcd
+TS_DISCO_F746NG ts; //objeto de controle do TOUCH
+
+//pressionou o botão
+void pressed()
+{
+    led = 1; //ativa o led
+}
+//soltou o botão
+void released()
+{
+    led = 0; //desativa o led
+}
+
+int main()
+{
+    // Assign functions to button
+    button.fall(&released); //botão solto
+    button.rise(&pressed); //botão pressionado
+    
+    TS_StateTypeDef TS_State; //variavel de controle para identificar toque na tela
+    uint16_t x, y; 
+    uint8_t status; 
+    status = ts.Init(lcd.GetXSize(), lcd.GetYSize()); //inicializa o TOUCH
+    
+    //touch inicializado com sucesso
+    if (status != TS_OK) {
+        lcd.Clear(LCD_COLOR_RED);
+        lcd.SetBackColor(LCD_COLOR_RED);
+        lcd.SetTextColor(LCD_COLOR_WHITE);
+        lcd.DisplayStringAt(0, LINE(5), (uint8_t *)"TOUCHSCREEN INIT FAIL", CENTER_MODE);
+    } else { //touch com falha
+        lcd.Clear(LCD_COLOR_GREEN);
+        lcd.SetBackColor(LCD_COLOR_GREEN);
+        lcd.SetTextColor(LCD_COLOR_WHITE);
+        lcd.DisplayStringAt(0, LINE(5), (uint8_t *)"TOUCHSCREEN INIT OK", CENTER_MODE);
+    }
+    
+    wait(1);
+    lcd.Clear(LCD_COLOR_BLUE);
+    lcd.SetBackColor(LCD_COLOR_BLUE);
+    lcd.SetTextColor(LCD_COLOR_WHITE);
+    lcd.DrawCircle(230, 135, 40); //desenha o circulo na tela
+    
+    
+    while (1) {
+        
+        ts.GetState(&TS_State); //verifica toque na tela
+        if (TS_State.touchDetected) {   //houve toque
+                x = TS_State.touchX[0];
+                y = TS_State.touchY[0];  
+                double d = sqrt( pow(x - 230.0, 2.0) + pow(y - 135.0,2.0) ); //distancia entre o ponto tocado e o centro do circulo
+                if(d <= 40) //toque dentro do circulo
+                {
+                    status = 1; //controle que tocou no circulo
+                    lcd.FillCircle(230, 135, 40); //pinta o circulo de branco
+                    led = 1; //ativa o led
+                }
+        }
+        else { //sem toque detectado
+            if(status == 1) { //se anteriormente tocou no circulo
+                lcd.Clear(LCD_COLOR_BLUE); //limpa a tela 
+                lcd.DrawCircle(230, 135, 40); //desenha o circulo
+                status = 0; //controle que nao tocou no circulo
+                led = 0; //desativa o led
+            }
+        }
+
+            
+    }
+}
diff -r 000000000000 -r c6d1896596c0 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Sep 06 21:27:41 2018 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/a7c7b631e539
\ No newline at end of file