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

Files at this revision

API Documentation at this revision

Comitter:
pampt
Date:
Thu Feb 02 06:12:19 2017 +0000
Parent:
4:16afa8576091
Child:
6:c1cf28acee3f
Commit message:
Working. MCP3221 ADC read stops DrawBitmap from working

Changed in this revision

MCP3221.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
--- a/MCP3221.lib	Wed Feb 01 23:07:47 2017 +0000
+++ b/MCP3221.lib	Thu Feb 02 06:12:19 2017 +0000
@@ -1,1 +1,1 @@
-http://developer.mbed.org/users/DaveStyles/code/MCP3221/#db4e3d0374fe
+http://developer.mbed.org/users/DaveStyles/code/MCP3221/#2921687d299e
--- a/main.cpp	Wed Feb 01 23:07:47 2017 +0000
+++ b/main.cpp	Thu Feb 02 06:12:19 2017 +0000
@@ -4,10 +4,12 @@
 #include "MCP3221.h"
 #include "Peter.h"
 
+#define MCP3221_REF 5.12 /* MCP3221 ADC reference (supply) voltage */
+
 LCD_DISCO_F746NG lcd;
 TS_DISCO_F746NG ts;
-MCP3221 adc(PB_9, PB_8, 4.096); // sda, scl, supply voltage
 DigitalOut led1(LED1);
+MCP3221 adc(PB_9, PB_8, MCP3221_REF); // sda, scl, reference (supply) voltage
 
 int main()
 {
@@ -22,20 +24,22 @@
     lcd.DrawBitmap(0, 0, (uint8_t *)peter_file);
 
     // Set display text colours
-    lcd.SetBackColor(LCD_COLOR_ORANGE);
-    lcd.SetTextColor(LCD_COLOR_CYAN);
+    lcd.SetBackColor(LCD_COLOR_DARKGREEN);
+    lcd.SetTextColor(LCD_COLOR_LIGHTGRAY);
 
     while(1) {
+
         // Display touch message
         ts.GetState(&TS_State);
         if (TS_State.touchDetected) {
-            lcd.DisplayStringAt(0, LINE(5), (uint8_t *)"TOUCH DETECTED!  ", CENTER_MODE);
+            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.DisplayStringAt(0, LINE(5), (uint8_t *)" NO TOUCH DETECTED ", CENTER_MODE);
         }
 
-        // Display ADC reading
-        sprintf((char*)text, "ADC=%f   ", adc.read());
+        // Read and scale ADC result
+        sprintf((char*)text, " ADC=%.3f ", adc.read());
+//        sprintf((char*)text, " ADC=%.3f ", 1.234);
         lcd.DisplayStringAt(0, LINE(8), (uint8_t *)&text, CENTER_MODE);
 
         led1 = !led1;