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
main.cpp@7:0d47aa3f72a7, 2017-02-02 (annotated)
- Committer:
- pampt
- Date:
- Thu Feb 02 07:41:03 2017 +0000
- Revision:
- 7:0d47aa3f72a7
- Parent:
- 6:c1cf28acee3f
A simple combination of DISCO-F746NG_LCD, DISCO-F746NG_TS and MCP3221 to demonstrate the issue where MCP3221 I2C ADC read stops DrawBitmap from working.
Who changed what in which revision?
User | Revision | Line number | New 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 | 6:c1cf28acee3f | 26 | // Display circle |
pampt | 6:c1cf28acee3f | 27 | lcd.SetTextColor(LCD_COLOR_RED); |
pampt | 6:c1cf28acee3f | 28 | lcd.FillCircle(50, 200, 40); |
pampt | 6:c1cf28acee3f | 29 | |
pampt | 4:16afa8576091 | 30 | // Set display text colours |
pampt | 5:59021306be0f | 31 | lcd.SetBackColor(LCD_COLOR_DARKGREEN); |
pampt | 5:59021306be0f | 32 | lcd.SetTextColor(LCD_COLOR_LIGHTGRAY); |
bcostm | 0:b045ca817e2c | 33 | |
pampt | 4:16afa8576091 | 34 | while(1) { |
pampt | 5:59021306be0f | 35 | |
pampt | 4:16afa8576091 | 36 | // Display touch message |
pampt | 4:16afa8576091 | 37 | ts.GetState(&TS_State); |
pampt | 4:16afa8576091 | 38 | if (TS_State.touchDetected) { |
pampt | 5:59021306be0f | 39 | lcd.DisplayStringAt(0, LINE(5), (uint8_t *)" TOUCH DETECTED! ", CENTER_MODE); |
pampt | 4:16afa8576091 | 40 | } else { |
pampt | 5:59021306be0f | 41 | lcd.DisplayStringAt(0, LINE(5), (uint8_t *)" NO TOUCH DETECTED ", CENTER_MODE); |
pampt | 4:16afa8576091 | 42 | } |
bcostm | 0:b045ca817e2c | 43 | |
pampt | 5:59021306be0f | 44 | // Read and scale ADC result |
pampt | 5:59021306be0f | 45 | sprintf((char*)text, " ADC=%.3f ", adc.read()); |
pampt | 5:59021306be0f | 46 | // sprintf((char*)text, " ADC=%.3f ", 1.234); |
pampt | 4:16afa8576091 | 47 | lcd.DisplayStringAt(0, LINE(8), (uint8_t *)&text, CENTER_MODE); |
bcostm | 0:b045ca817e2c | 48 | |
pampt | 4:16afa8576091 | 49 | led1 = !led1; |
bcostm | 0:b045ca817e2c | 50 | } |
bcostm | 0:b045ca817e2c | 51 | } |