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: wifi-ism43362
Dependents: DigitalOut DigitalOut
OLEDDisplay.h
00001 /* IoTKit OLED Display Library 00002 * Copyright (c) 2016 Marcel mc-b Bernet 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #include "mbed.h" 00018 #include <stdarg.h> 00019 #include "Adafruit_SSD1306.h" 00020 00021 #ifndef OLED_DISPLAY 00022 #define OLED_DISPLAY 00023 00024 /** OLED Display 00025 * 00026 * Vereinfachte Version zur Ansteuerung eines Displays 00027 * auf Basis von I2C und SSD1306 Interface 00028 * 00029 * Example: 00030 * @code 00031 * #include "mbed.h" 00032 * #include "OLEDDisplay.h" 00033 * 00034 * DigitalOut led( D10 ); 00035 * OLEDDisplay oled; 00036 * 00037 * int main() 00038 * { 00039 * int i = 0; 00040 * oled.clear(); 00041 * oled.printf( "Test\r\n" ); 00042 * 00043 * while (true) 00044 * { 00045 * oled.cursor( 1, 0 ); 00046 * oled.printf( "ON %d, %d\n", led.read(), i ); 00047 * led = 1; 00048 * wait( 1.0f ); 00049 * 00050 * oled.cursor( 2, 0 ); 00051 * oled.printf( "OFF %d, %d\n", led.read(), i ); 00052 * led = 0; 00053 * i++; 00054 * wait( 1.0f ); 00055 * } 00056 * } 00057 * @endcode 00058 */ 00059 00060 class OLEDDisplay 00061 { 00062 public: 00063 OLEDDisplay( PinName rst = D9, PinName sca = D14, PinName scl = D15, uint8_t addr = 0x78 ) : i2c( sca, scl ), oled( i2c, rst, addr ) 00064 { 00065 } 00066 00067 /** clear Display */ 00068 void clear() 00069 { 00070 oled.clearDisplay(); 00071 oled.setTextCursor( 0, 0 ); 00072 00073 } 00074 /** Set the display rotation, 1 = down, 2 = up, 3 = left, or 4 = right*/ 00075 void setRotation(uint8_t r) 00076 { 00077 oled.setRotation( r ); 00078 } 00079 00080 /** printf formatted with display */ 00081 void printf( const char *format, ... ) 00082 { 00083 static char buffer[128]; 00084 00085 va_list args; 00086 va_start(args, format); 00087 vsprintf(buffer, format, args); 00088 va_end(args); 00089 00090 oled.printf( buffer ); 00091 oled.display(); 00092 } 00093 00094 /// Set the text cursor location, based on the size of the text 00095 void cursor( int16_t y, int16_t x ) 00096 { 00097 oled.setTextCursor( x * 6 , y * 8 ); 00098 } 00099 00100 00101 private: 00102 I2C i2c; 00103 Adafruit_SSD1306_I2c oled; 00104 }; 00105 00106 #endif // OLED_DISPLAY
Generated on Thu Jul 14 2022 01:22:20 by
