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:
4:b3559f0f6072
Parent:
3:64fb84822c90
Child:
5:58208433fe78
--- a/main.cpp	Thu Oct 01 05:28:04 2020 +0000
+++ b/main.cpp	Mon Feb 22 18:03:21 2021 +0000
@@ -20,7 +20,7 @@
 * Please connect L432KC - Pmod_OLEDrgb with lines:
 * L432KC D13 - OLED 4 SCK   hardware defined for the SPI
 * L432KC D11 - OLED 2 MOSI  hardware definef for the SPI
-* L432KC D9  - OLED 1 CS   or any other free
+* L432KC A7  - OLED 1 CS   or any other free
 * L432KC D10 - OLED 7 DC   or any other free
 * L432KC D6  - OLED 8 RES   or any other free
 *  VCC     - OLED 9 VCCEN  Enable - VCC
@@ -46,10 +46,10 @@
                                 // Adafruit_SSD1331_MbedOS6 by Timo Karppinen
                                 // Adafruit-GFX-MbedOS6 by Timo Karppinen             
 // PmodOLEDrgb
-Adafruit_SSD1331 OLED(D9, D6, D10, D11, NC, D13); // cs, res, dc, mosi, (nc), sck  
+Adafruit_SSD1331 OLED(A7, 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 
+DigitalOut LED(D1);     // 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);
 DigitalOut PMODEN(D5);
@@ -69,24 +69,26 @@
 int millivolt = 0;
 void getADC();
 
-char Time[50],Date[50];
+char Time[32];
+
 void getTime();
 int first = 0;
 
 int main()
 {
   // Showing with a LED that program has started
-        //    LED = 0;
+        LED = 0;
         VCCEN = 1;    // if you did not connect VCCEN permanently to Vcc
         PMODEN = 1;   // if you did not connect PMODEN permanently to Vcc
         ThisThread::sleep_for(2000ms);
-        //    LED = 1;
+        LED = 1;
         ThisThread::sleep_for(2000ms);
-        //  LED = 0;
+        LED = 0;
+  // Setting the time
+  set_time(1614012790);  // Set RTC time to " https://www.epochconverter.com/ "     
   // Initalize the PmodOLEDrgb, the library includes SPI and there is
   // no need to initialize the SPI in the main.cpp   
         OLED.begin(); // initialization of display object
-        
         OLED.clearScreen();   
 
     while (true) {
@@ -113,57 +115,58 @@
                 OLED.fillRoundRect(35, 5, 30, 40, 1, White);
                 OLED.fillRoundRect(65, 5, 30, 40, 1, Red);
                 OLED.fillCircle(90, 55, 5, Yellow); // yellow circle with radius=5 in x=90 and y=55
-                ThisThread::sleep_for(2s); // wait 2 s
+                ThisThread::sleep_for(1s); // wait 1 s
             }
 
-        getTime();
+       
+        //ThisThread::sleep_for(300ms);
         OLED.clearScreen();
-        OLED.fillScreen(Black); // background screen in black
+        OLED.fillScreen(Blue); // background screen in blue
         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");
+        getTime();
+        OLED.printf(" at %s \n",Time);
         getADC(); 
         OLED.printf("VOLT :%d.%03d\r\n", volt, millivolt);
 
-        if (ADCScaledF > 2.00)
+        if (ADCScaledF > 2.70)
         { 
             OLED.setTextColor(Yellow);
-            OLED.printf("Be aware of reaching the limit");
-            OLED.fillRoundRect(10, 35, 50, 3 , 1, Yellow);
+            OLED.printf("Be aware of reaching the limit\n");
+            OLED.drawFastHLine(10, 43, 50, Yellow);
         }
-        OLED.setCursor(0,40); // cursor is in x=0 and y=40
+        OLED.setCursor(0,46); // cursor is in x=0 and y=40
         OLED.printf("Wait a moment !");
-        OLED.drawFastHLine(1, 60, OLED.width()-1, Blue); // blue line x=1 to screen width-1 and y=60
-        printf("printed on OLED");
+        OLED.drawFastHLine(1, OLED.height()-1, OLED.width()-1, Red); //RED line x=1 to screen width-1 and 
+                                                                    // y=screen height-1
+        //printf("printed on OLED\n\n");
         
-        ThisThread::sleep_for(3000ms);
+        ThisThread::sleep_for(1000ms);
 }
 }
 
 void getTime()
 {    
-    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);
+    time_t seconds = time(NULL);   //  https://os.mbed.com/docs/mbed-os/v6.7/apis/time.html
+    strftime(Time,32,"%I:%M:%p\n", localtime(&seconds));
+    //printf("Recorded :%s \r\n", Time); // in mbed OS 6.7 interferes with OLED.printf  !!!
+   
 }
 
 void getADC()
 {
-    static int count = 200;     // variable value like it would be from Analog to Digital Converter
+    static int count = 200;     // value like it would be from a 12 bit Analog to Digital Converter
    
-    count = count + 10;
+    count = count + 82;
     if (count > 4095){
         count = 200;
         }
     
-    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.
+    ADCScaledF = (float(count))*(float(3.3)/4095); // The 0.00 V to  3.30 V corresponds 32 bit floating point.
     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
+    //printf("ADC   :%d \r\n",count);   // in mbed OS 6.7 interferes with OLED.printf  !!!
+    //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