Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: Adafruit-GFX-MbedOS6
main.cpp
00001 /* mbed Microcontroller Library 00002 * Copyright (c) 2019 ARM Limited 00003 * SPDX-License-Identifier: Apache-2.0 00004 ************************************************************************ 00005 * 00006 * Commissioning test for the L432KC and the Pmod small OLED display 00007 * 00008 ************************************************************************* 00009 * Description: McLab10_OLEDrgb_L432KC_OS60_tk2 00010 * "Test module Pmod Digilent Lextronic" will be displayed on OLEDrgb module 00011 * with different size and colors..... and later the variable values. 00012 * 00013 * Material 00014 * 1. ST L432KC ( or some other micro controller board with SPI communication ) 00015 * 2. Digilent Pmod OLEDrgb and the libraries 00016 * Adafruit_SSD1331_Mbed, select the version "Timo Karppine" which is modified for OS6.nn 00017 * Adafruit-GFX, select the version "Timo Karppine" which is modified for OS6.nn 00018 * These libraries can be found with search on the page 00019 * https://www.mbed.com/en/platform/mbed-os/ 00020 * Please connect L432KC - Pmod_OLEDrgb with lines: 00021 * L432KC D13 - OLED 4 SCK hardware defined for the SPI 00022 * L432KC D11 - OLED 2 MOSI hardware definef for the SPI 00023 * L432KC A7 - OLED 1 CS or any other free 00024 * L432KC D10 - OLED 7 DC or any other free 00025 * L432KC A6 - OLED 8 RES or any other free 00026 * L432KC D2 - OLED 9 VCCEN Enable, or connect to VCC 00027 * L432KC D3 - OLED10 PMODEN Pmod Enable, or connect to VCC 00028 * GND - OLED 5 Ground 00029 * VCC - OLED 6 Power supply 3.3 V 00030 * L432KC 3V3 - VCC L432 supplying 3.3 V 00031 * L432KC GND - GND Ground 00032 * 00033 ************************************************************************* 00034 * Updated for OS67, ... OS6.15 compiles OK. 00035 * Timo Karppinen 3.10.2022 SPDX-License-Identifier: Apache-2.0 00036 **************************************************************/ 00037 00038 #include "mbed.h" 00039 #include "Adafruit_SSD1331.h" // By using the Adafruit SSD1331 library and Adafruit GFX library 00040 #include "Adafruit_GFX.h" // we will get similar code working than in Arduino-boards. 00041 // There are other SSD1331 libraries, too. 00042 // https://os.mbed.com/search/?q=ssd1331 00043 // The tested are: 00044 // Adafruit_SSD1331_MbedOS6 by Timo Karppinen 00045 // Adafruit-GFX-MbedOS6 by Timo Karppinen 00046 // PmodOLEDrgb 00047 Adafruit_SSD1331 OLED(A7, A6, D10, D11, NC, D13); // cs, res, dc, mosi, (nc), sck 00048 00049 00050 DigitalOut LED(D1); // LED1, LED2, LED3 and LED4 are the D13 PB_3 pin in this board and 00051 //can not be used as a LED because of the SPI 00052 DigitalOut VCCEN(D2); 00053 DigitalOut PMODEN(D3); 00054 00055 // Definition of colours on the OLED display 00056 #define Black 0x0000 00057 #define Blue 0x001F 00058 #define Red 0xF800 00059 #define Green 0x07E0 00060 #define Cyan 0x07FF 00061 #define Magenta 0xF81F 00062 #define Yellow 0xFFE0 00063 #define White 0xFFFF 00064 00065 float ADCScaledF = 0; // 32 bit floating point 00066 int volt = 0; 00067 int millivolt = 0; 00068 void getADC(); 00069 00070 char Time[32]; 00071 00072 void getTime(); 00073 int first = 0; 00074 00075 int main() 00076 { 00077 // Showing with a LED that program has started 00078 LED = 0; 00079 VCCEN = 1; // if you did not connect VCCEN permanently to Vcc 00080 PMODEN = 1; // if you did not connect PMODEN permanently to Vcc 00081 ThisThread::sleep_for(2000ms); 00082 LED = 1; 00083 ThisThread::sleep_for(2000ms); 00084 LED = 0; 00085 // Setting the time 00086 set_time(1614069522); // Set RTC time to " https://www.epochconverter.com/ " 00087 // Initalize the PmodOLEDrgb, the library includes SPI and there is 00088 // no need to initialize the SPI in the main.cpp 00089 OLED.begin(); // initialization of display object 00090 OLED.clearScreen(); 00091 00092 while (true) { 00093 while(first < 3) 00094 { 00095 first += 1; 00096 OLED.fillScreen(Black); // background screen in black 00097 OLED.setTextColor(Cyan); // colour of text in cyan 00098 OLED.setCursor(0,0); // cursor is in x=0 and y=15 00099 OLED.printf("Test module Pmod"); // display text 00100 ThisThread::sleep_for(500ms); // wait 500 ms 00101 OLED.setCursor(0,15); // cursor is in x=0 and y=15 00102 OLED.setTextSize(2); // size of text 00103 OLED.setTextColor(Red); // text in red colour 00104 OLED.printf("DIGILENT"); // display text 00105 OLED.setCursor(20,40); // cursor is in x=20 and y=40 00106 OLED.setTextSize(1); // size of text 00107 OLED.setTextColor(Green); // text in green colour 00108 OLED.printf("LEXTRONIC"); // display text 00109 OLED.drawFastHLine(1, 60, OLED.width()-1, Blue); //blue line x=1, width-1 and y=60 00110 ThisThread::sleep_for(2s); // wait 2 s 00111 OLED.fillScreen(Black); // background display in black (erase display) 00112 OLED.fillRoundRect(5, 5, 30, 40, 1, Blue); // French flag bleu blanc rouge 00113 OLED.fillRoundRect(35, 5, 30, 40, 1, White); 00114 OLED.fillRoundRect(65, 5, 30, 40, 1, Red); 00115 OLED.fillCircle(90, 55, 5, Yellow); // yellow circle with radius=5 in x=90 and y=55 00116 ThisThread::sleep_for(1s); // wait 1 s 00117 } 00118 00119 00120 //ThisThread::sleep_for(300ms); 00121 OLED.clearScreen(); 00122 OLED.fillScreen(Blue); // background screen in blue 00123 OLED.setTextColor(Cyan); // colour of text in cyan 00124 OLED.setCursor(0,0); // cursor is in x=0 and y=0 00125 OLED.printf("Rec"); 00126 getTime(); 00127 OLED.printf(" at %s \n",Time); 00128 getADC(); 00129 OLED.printf("VOLT :%d.%03d\r\n", volt, millivolt); 00130 00131 if (ADCScaledF > 2.70) 00132 { 00133 OLED.setTextColor(Yellow); 00134 OLED.printf("Be aware of reaching the limit\n"); 00135 OLED.drawFastHLine(10, 43, 50, Yellow); 00136 } 00137 OLED.setCursor(0,46); // cursor is in x=0 and y=40 00138 OLED.printf("Wait a moment !"); 00139 OLED.drawFastHLine(1, OLED.height()-1, OLED.width()-1, Red); //RED line x=1 to screen width-1 and 00140 // y=screen height-1 00141 //printf("printed on OLED\n\n"); // OLED.printf() is using the same resource!! 00142 00143 ThisThread::sleep_for(1000ms); 00144 } 00145 } 00146 00147 void getTime() 00148 { 00149 time_t seconds = time(NULL); // https://os.mbed.com/docs/mbed-os/v6.7/apis/time.html 00150 strftime(Time,32,"%I:%M:%p\n", localtime(&seconds)); 00151 //printf("Recorded :%s \r\n", Time); // in mbed OS 6.7 interferes with OLED.printf !!! 00152 00153 } 00154 00155 void getADC() 00156 { 00157 static int count = 200; // value like it would be from a 12 bit Analog to Digital Converter 00158 00159 count = count + 82; 00160 if (count > 4095){ 00161 count = 200; 00162 } 00163 00164 ADCScaledF = (float(count))*(float(3.3)/4095); // The 0.00 V to 3.30 V corresponds 32 bit floating point. 00165 volt = (int)ADCScaledF; // The OS6 does not include floating point printf !!! 00166 millivolt = ((int)(ADCScaledF*1000))% 1000; // Millivolts counted with c++ modulus operator 00167 //printf("ADC :%d \r\n",count); // in mbed OS 6.7 interferes with OLED.printf !!! 00168 //printf("VOLT :%d.%03d\r\n", volt, millivolt); // millivolts with preceeding zeros and three digits 00169 ThisThread::sleep_for(100ms); 00170 }
Generated on Tue Oct 4 2022 08:50:50 by
1.7.2