A simple demonstration of the DISCO-F746NG LCD, TouchScreen and MCP3221 I2C ADC.
Dependencies: BSP_DISCO_F746NG LCD_DISCO_F746NG MCP3221 TS_DISCO_F746NG mbed
Fork of DISCO-F746NG_LCD_demo by
Diff: main.cpp
- Revision:
- 4:16afa8576091
- Parent:
- 0:b045ca817e2c
- Child:
- 5:59021306be0f
--- a/main.cpp Thu Nov 10 15:18:47 2016 +0000 +++ b/main.cpp Wed Feb 01 23:07:47 2017 +0000 @@ -1,46 +1,43 @@ #include "mbed.h" #include "LCD_DISCO_F746NG.h" +#include "TS_DISCO_F746NG.h" +#include "MCP3221.h" +#include "Peter.h" LCD_DISCO_F746NG lcd; - +TS_DISCO_F746NG ts; +MCP3221 adc(PB_9, PB_8, 4.096); // sda, scl, supply voltage DigitalOut led1(LED1); int main() -{ +{ + TS_StateTypeDef TS_State; + uint8_t text[30]; + led1 = 1; - lcd.DisplayStringAt(0, LINE(1), (uint8_t *)"MBED EXAMPLE", CENTER_MODE); - wait(1); - - while(1) - { - lcd.Clear(LCD_COLOR_BLUE); - lcd.SetBackColor(LCD_COLOR_BLUE); - lcd.SetTextColor(LCD_COLOR_WHITE); - wait(0.3); - lcd.DisplayStringAt(0, LINE(5), (uint8_t *)"DISCOVERY STM32F746NG", CENTER_MODE); - wait(1); + // Display bitmap image + lcd.Clear(LCD_COLOR_WHITE); + lcd.SetBackColor(LCD_COLOR_WHITE); + lcd.DrawBitmap(0, 0, (uint8_t *)peter_file); + + // Set display text colours + lcd.SetBackColor(LCD_COLOR_ORANGE); + lcd.SetTextColor(LCD_COLOR_CYAN); - lcd.Clear(LCD_COLOR_GREEN); - - lcd.SetTextColor(LCD_COLOR_BLUE); - lcd.DrawRect(10, 20, 50, 50); - wait(0.1); - lcd.SetTextColor(LCD_COLOR_BROWN); - lcd.DrawCircle(80, 80, 50); - wait(0.1); - lcd.SetTextColor(LCD_COLOR_YELLOW); - lcd.DrawEllipse(150, 150, 50, 100); - wait(0.1); - lcd.SetTextColor(LCD_COLOR_RED); - lcd.FillCircle(200, 200, 40); - wait(1); + while(1) { + // Display touch message + ts.GetState(&TS_State); + if (TS_State.touchDetected) { + lcd.DisplayStringAt(0, LINE(5), (uint8_t *)"TOUCH DETECTED! ", CENTER_MODE); + } else { + lcd.DisplayStringAt(0, LINE(5), (uint8_t *)"NO TOUCH DETECTED", CENTER_MODE); + } - lcd.SetBackColor(LCD_COLOR_ORANGE); - lcd.SetTextColor(LCD_COLOR_CYAN); - lcd.DisplayStringAt(0, LINE(5), (uint8_t *)"HAVE FUN !!!", CENTER_MODE); - wait(1); + // Display ADC reading + sprintf((char*)text, "ADC=%f ", adc.read()); + lcd.DisplayStringAt(0, LINE(8), (uint8_t *)&text, CENTER_MODE); - led1 = !led1; + led1 = !led1; } }