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 ST

Committer:
pampt
Date:
Thu Feb 02 06:12:19 2017 +0000
Revision:
5:59021306be0f
Parent:
4:16afa8576091
Child:
6:c1cf28acee3f
Working. MCP3221 ADC read stops DrawBitmap from working

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bcostm 0:b045ca817e2c 1 #include "mbed.h"
bcostm 0:b045ca817e2c 2 #include "LCD_DISCO_F746NG.h"
pampt 4:16afa8576091 3 #include "TS_DISCO_F746NG.h"
pampt 4:16afa8576091 4 #include "MCP3221.h"
pampt 4:16afa8576091 5 #include "Peter.h"
bcostm 0:b045ca817e2c 6
pampt 5:59021306be0f 7 #define MCP3221_REF 5.12 /* MCP3221 ADC reference (supply) voltage */
pampt 5:59021306be0f 8
bcostm 0:b045ca817e2c 9 LCD_DISCO_F746NG lcd;
pampt 4:16afa8576091 10 TS_DISCO_F746NG ts;
bcostm 0:b045ca817e2c 11 DigitalOut led1(LED1);
pampt 5:59021306be0f 12 MCP3221 adc(PB_9, PB_8, MCP3221_REF); // sda, scl, reference (supply) voltage
bcostm 0:b045ca817e2c 13
bcostm 0:b045ca817e2c 14 int main()
pampt 4:16afa8576091 15 {
pampt 4:16afa8576091 16 TS_StateTypeDef TS_State;
pampt 4:16afa8576091 17 uint8_t text[30];
pampt 4:16afa8576091 18
bcostm 0:b045ca817e2c 19 led1 = 1;
bcostm 0:b045ca817e2c 20
pampt 4:16afa8576091 21 // Display bitmap image
pampt 4:16afa8576091 22 lcd.Clear(LCD_COLOR_WHITE);
pampt 4:16afa8576091 23 lcd.SetBackColor(LCD_COLOR_WHITE);
pampt 4:16afa8576091 24 lcd.DrawBitmap(0, 0, (uint8_t *)peter_file);
pampt 4:16afa8576091 25
pampt 4:16afa8576091 26 // Set display text colours
pampt 5:59021306be0f 27 lcd.SetBackColor(LCD_COLOR_DARKGREEN);
pampt 5:59021306be0f 28 lcd.SetTextColor(LCD_COLOR_LIGHTGRAY);
bcostm 0:b045ca817e2c 29
pampt 4:16afa8576091 30 while(1) {
pampt 5:59021306be0f 31
pampt 4:16afa8576091 32 // Display touch message
pampt 4:16afa8576091 33 ts.GetState(&TS_State);
pampt 4:16afa8576091 34 if (TS_State.touchDetected) {
pampt 5:59021306be0f 35 lcd.DisplayStringAt(0, LINE(5), (uint8_t *)" TOUCH DETECTED! ", CENTER_MODE);
pampt 4:16afa8576091 36 } else {
pampt 5:59021306be0f 37 lcd.DisplayStringAt(0, LINE(5), (uint8_t *)" NO TOUCH DETECTED ", CENTER_MODE);
pampt 4:16afa8576091 38 }
bcostm 0:b045ca817e2c 39
pampt 5:59021306be0f 40 // Read and scale ADC result
pampt 5:59021306be0f 41 sprintf((char*)text, " ADC=%.3f ", adc.read());
pampt 5:59021306be0f 42 // sprintf((char*)text, " ADC=%.3f ", 1.234);
pampt 4:16afa8576091 43 lcd.DisplayStringAt(0, LINE(8), (uint8_t *)&text, CENTER_MODE);
bcostm 0:b045ca817e2c 44
pampt 4:16afa8576091 45 led1 = !led1;
bcostm 0:b045ca817e2c 46 }
bcostm 0:b045ca817e2c 47 }