The code is developed for the hardware NUCLEO-L432KC and Digilent Pmod OLEDrgb. The purpose is to make students learn the development process and test that the hardware works fine. For converting this to Mbed OS 6 Adafruit_GFX.h needed to add #include "Stream.h" in beginning of the Adafruit_GFX.h Adafruit_SSD1331.cpp wait_ms(200) replaced with ThisThread::sleep_for(200ms); for all the similar wait_ms lines.

Dependencies:   Adafruit-GFX-MbedOS6

Revision:
3:64fb84822c90
Parent:
2:29bb1ef0d6cd
Child:
4:b3559f0f6072
--- a/main.cpp	Mon Aug 31 10:48:14 2020 +0000
+++ b/main.cpp	Thu Oct 01 05:28:04 2020 +0000
@@ -48,6 +48,7 @@
 // PmodOLEDrgb
 Adafruit_SSD1331 OLED(D9, D6, D10, D11, NC, D13); // cs, res, dc, mosi, (nc), sck  
 
+
 //DigitalOut LED(LED1);     // LED1, LED2, LED3 and LED4 are the D13 PB_3 pin in this board and 
                             //can not be used as a LED because of the SPI
 DigitalOut VCCEN(D3);
@@ -63,8 +64,10 @@
 #define Yellow 0xFFE0
 #define White 0xFFFF
 
-float stepsScaledF = 0;       // 32 bit floating point
-void getSTEPS();
+float ADCScaledF = 0;       // 32 bit floating point
+int volt = 0;
+int millivolt = 0;
+void getADC();
 
 char Time[50],Date[50];
 void getTime();
@@ -119,12 +122,12 @@
         OLED.setTextColor(Cyan); // colour of text in cyan
         ThisThread::sleep_for(300ms);
         OLED.setCursor(0,0); // cursor is in x=0 and y=0
-        OLED.printf("Rec '%s' \n",Time);
+        OLED.printf("Rec :%s \n",Time);
         
-        getSTEPS(); 
-        OLED.printf("value = '%0.1f' \n",stepsScaledF);
+        getADC(); 
+        OLED.printf("VOLT :%d.%03d\r\n", volt, millivolt);
 
-        if (stepsScaledF > 2.00)
+        if (ADCScaledF > 2.00)
         { 
             OLED.setTextColor(Yellow);
             OLED.printf("Be aware of reaching the limit");
@@ -144,21 +147,23 @@
     time_t seconds = time(NULL);   //  https://os.mbed.com/docs/mbed-os/v6.2/apis/time.html
     strftime(Time,40,"%H:%M:%S", localtime(&seconds));
     strftime(Date,40,"%d-%b-%Y", localtime(&seconds));
-    printf("Recorded '%s' \r\n",Time);
+    printf("Recorded :%s \r\n",Time);
 }
 
-void getSTEPS()
+void getADC()
 {
-    static int count; 
+    static int count = 200;     // variable value like it would be from Analog to Digital Converter
    
-    count = count + 100;
+    count = count + 10;
     if (count > 4095){
-        count = 0;
+        count = 200;
         }
     
-    stepsScaledF = (float(count))*(float(2.50)/4095); // The value 2.50 is 64 bit double precision floating point of type double.
+    ADCScaledF = (float(count))*(float(2.50)/4095); // The value 2.50 is 64 bit double precision floating point of type double.
                                                 // Conversions to 32 bit floating point of type float.
-    printf("Counter value '%d' \r\n",count);
-    printf("Scaled output  '%0.1f' \r\n",stepsScaledF);
+    volt = (int)ADCScaledF;                     // The OS6 does not include floating point printf !!!
+    millivolt = ((int)(ADCScaledF*1000))% 1000; // Millivolts counted with c++ modulus operator
+    printf("ADC   :%d \r\n",count);
+    printf("VOLT  :%d.%03d\r\n", volt, millivolt); // millivolts with preceeding zeros and three digits
     ThisThread::sleep_for(100ms);
 }
\ No newline at end of file