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.
Dependents: UltraschallSensor_LowLevelV2
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 /** Set the display rotation, 1 = down, 2 = up, 3 = left, or 4 = right*/ 00074 void setRotation(uint8_t r) 00075 { 00076 oled.setRotation( r ); 00077 } 00078 00079 /** printf formatted with display */ 00080 void printf( const char *format, ... ) 00081 { 00082 static char buffer[128]; 00083 00084 va_list args; 00085 va_start(args, format); 00086 vsprintf(buffer, format, args); 00087 va_end(args); 00088 00089 oled.printf( buffer ); 00090 oled.display(); 00091 } 00092 00093 /// Set the text cursor location, based on the size of the text 00094 void cursor( int16_t y, int16_t x ) 00095 { 00096 oled.setTextCursor( x * 6 , y * 8 ); 00097 } 00098 00099 00100 private: 00101 I2C i2c; 00102 Adafruit_SSD1306_I2c oled; 00103 }; 00104 00105 #endif // OLED_DISPLAY
Generated on Sun Jul 17 2022 02:57:33 by
