Demo program for the Oled display
main.cpp@0:94bf5ec759da, 2015-01-08 (annotated)
- Committer:
- star297
- Date:
- Thu Jan 08 12:05:23 2015 +0000
- Revision:
- 0:94bf5ec759da
- Child:
- 1:793dbd6d6498
v1.0 demo program
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
star297 | 0:94bf5ec759da | 1 | #include "mbed.h" |
star297 | 0:94bf5ec759da | 2 | #include "OLED32028P1T.h" |
star297 | 0:94bf5ec759da | 3 | |
star297 | 0:94bf5ec759da | 4 | /* |
star297 | 0:94bf5ec759da | 5 | This display requires 5v, 200mA power supply, serial and reset connections are 3.3v - 5v. |
star297 | 0:94bf5ec759da | 6 | Set Oled to any serial port. It is Target dependant, some platforms may not work at |
star297 | 0:94bf5ec759da | 7 | higher baud rates. Set baud rates as per the list in .cpp file, NOT in the program. |
star297 | 0:94bf5ec759da | 8 | Freescale KLxx MCU's will only work upt to 128k baud and some have been defined. |
star297 | 0:94bf5ec759da | 9 | */ |
star297 | 0:94bf5ec759da | 10 | |
star297 | 0:94bf5ec759da | 11 | OLED32028P1T oled(PTB17,PTB16,PTC0); // Oled Display TX, RX, RESET |
star297 | 0:94bf5ec759da | 12 | |
star297 | 0:94bf5ec759da | 13 | char timebuffer[50]; |
star297 | 0:94bf5ec759da | 14 | char datebuffer[50]; |
star297 | 0:94bf5ec759da | 15 | |
star297 | 0:94bf5ec759da | 16 | int main() { |
star297 | 0:94bf5ec759da | 17 | |
star297 | 0:94bf5ec759da | 18 | oled.init(); // initialise the display. This will start at 9600 baud then auto set |
star297 | 0:94bf5ec759da | 19 | // to the higher baud rate as set in the .cpp file |
star297 | 0:94bf5ec759da | 20 | // This can be called at any time in the program to restart the display |
star297 | 0:94bf5ec759da | 21 | // if required, display power down for instance. |
star297 | 0:94bf5ec759da | 22 | |
star297 | 0:94bf5ec759da | 23 | oled.clear(); |
star297 | 0:94bf5ec759da | 24 | oled.setTextBackgroundType(TEXT_OPAQUE); |
star297 | 0:94bf5ec759da | 25 | oled.setFontColor(WHITE); // some predefined colours |
star297 | 0:94bf5ec759da | 26 | |
star297 | 0:94bf5ec759da | 27 | oled.drawText(1,1,(FONT12X16)," --RTC Clock Time-- ",oled.toRGB(255,255,255)); |
star297 | 0:94bf5ec759da | 28 | oled.setFontSize(FONT12X16); |
star297 | 0:94bf5ec759da | 29 | oled.setFontColor(oled.toRGB(255,255,0)); |
star297 | 0:94bf5ec759da | 30 | |
star297 | 0:94bf5ec759da | 31 | while(1){ |
star297 | 0:94bf5ec759da | 32 | |
star297 | 0:94bf5ec759da | 33 | time_t seconds = time(NULL); |
star297 | 0:94bf5ec759da | 34 | |
star297 | 0:94bf5ec759da | 35 | strftime(timebuffer, 32, "RTC %I:%M:%S %p", localtime(&seconds)); |
star297 | 0:94bf5ec759da | 36 | strftime(datebuffer, 32, "%a %d %b %Y ", localtime(&seconds)); |
star297 | 0:94bf5ec759da | 37 | |
star297 | 0:94bf5ec759da | 38 | oled.drawText(2,3,(FONT12X16),timebuffer,oled.toRGB(255,255,0)); // print using drawText is faster |
star297 | 0:94bf5ec759da | 39 | oled.drawText(2,4,(FONT12X16),datebuffer,oled.toRGB(255,128,0)); |
star297 | 0:94bf5ec759da | 40 | |
star297 | 0:94bf5ec759da | 41 | oled.locate(3,6); // print start posistion x,y in characters (not pixels) |
star297 | 0:94bf5ec759da | 42 | oled.setFontSize(FONT12X16); // Font size |
star297 | 0:94bf5ec759da | 43 | |
star297 | 0:94bf5ec759da | 44 | oled.setFontColor(oled.toRGB(255,255,255)); // 'R' 'G' 'B' can be set for upto 16 million colurs |
star297 | 0:94bf5ec759da | 45 | oled.printf(timebuffer); // print using printf is slower than drawText |
star297 | 0:94bf5ec759da | 46 | |
star297 | 0:94bf5ec759da | 47 | oled.locate(3,7); |
star297 | 0:94bf5ec759da | 48 | oled.printf(datebuffer); |
star297 | 0:94bf5ec759da | 49 | |
star297 | 0:94bf5ec759da | 50 | |
star297 | 0:94bf5ec759da | 51 | wait(.2); |
star297 | 0:94bf5ec759da | 52 | } |
star297 | 0:94bf5ec759da | 53 | } |