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@1:480364dcdacc, 2019-04-22 (annotated)
- Committer:
- marcel1691
- Date:
- Mon Apr 22 09:43:15 2019 +0000
- Revision:
- 1:480364dcdacc
Alle Pins und OLEDDisplay und Motor Library
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| marcel1691 | 1:480364dcdacc | 1 | /* IoTKit OLED Display Library |
| marcel1691 | 1:480364dcdacc | 2 | * Copyright (c) 2016 Marcel mc-b Bernet |
| marcel1691 | 1:480364dcdacc | 3 | * |
| marcel1691 | 1:480364dcdacc | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| marcel1691 | 1:480364dcdacc | 5 | * you may not use this file except in compliance with the License. |
| marcel1691 | 1:480364dcdacc | 6 | * You may obtain a copy of the License at |
| marcel1691 | 1:480364dcdacc | 7 | * |
| marcel1691 | 1:480364dcdacc | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| marcel1691 | 1:480364dcdacc | 9 | * |
| marcel1691 | 1:480364dcdacc | 10 | * Unless required by applicable law or agreed to in writing, software |
| marcel1691 | 1:480364dcdacc | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| marcel1691 | 1:480364dcdacc | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| marcel1691 | 1:480364dcdacc | 13 | * See the License for the specific language governing permissions and |
| marcel1691 | 1:480364dcdacc | 14 | * limitations under the License. |
| marcel1691 | 1:480364dcdacc | 15 | */ |
| marcel1691 | 1:480364dcdacc | 16 | |
| marcel1691 | 1:480364dcdacc | 17 | #include "mbed.h" |
| marcel1691 | 1:480364dcdacc | 18 | #include <stdarg.h> |
| marcel1691 | 1:480364dcdacc | 19 | #include "Adafruit_SSD1306.h" |
| marcel1691 | 1:480364dcdacc | 20 | |
| marcel1691 | 1:480364dcdacc | 21 | #ifndef OLED_DISPLAY |
| marcel1691 | 1:480364dcdacc | 22 | #define OLED_DISPLAY |
| marcel1691 | 1:480364dcdacc | 23 | |
| marcel1691 | 1:480364dcdacc | 24 | /** OLED Display |
| marcel1691 | 1:480364dcdacc | 25 | * |
| marcel1691 | 1:480364dcdacc | 26 | * Vereinfachte Version zur Ansteuerung eines Displays |
| marcel1691 | 1:480364dcdacc | 27 | * auf Basis von I2C und SSD1306 Interface |
| marcel1691 | 1:480364dcdacc | 28 | * |
| marcel1691 | 1:480364dcdacc | 29 | * Example: |
| marcel1691 | 1:480364dcdacc | 30 | * @code |
| marcel1691 | 1:480364dcdacc | 31 | * #include "mbed.h" |
| marcel1691 | 1:480364dcdacc | 32 | * #include "OLEDDisplay.h" |
| marcel1691 | 1:480364dcdacc | 33 | * |
| marcel1691 | 1:480364dcdacc | 34 | * DigitalOut led( D10 ); |
| marcel1691 | 1:480364dcdacc | 35 | * OLEDDisplay oled; |
| marcel1691 | 1:480364dcdacc | 36 | * |
| marcel1691 | 1:480364dcdacc | 37 | * int main() |
| marcel1691 | 1:480364dcdacc | 38 | * { |
| marcel1691 | 1:480364dcdacc | 39 | * int i = 0; |
| marcel1691 | 1:480364dcdacc | 40 | * oled.clear(); |
| marcel1691 | 1:480364dcdacc | 41 | * oled.printf( "Test\r\n" ); |
| marcel1691 | 1:480364dcdacc | 42 | * |
| marcel1691 | 1:480364dcdacc | 43 | * while (true) |
| marcel1691 | 1:480364dcdacc | 44 | * { |
| marcel1691 | 1:480364dcdacc | 45 | * oled.cursor( 1, 0 ); |
| marcel1691 | 1:480364dcdacc | 46 | * oled.printf( "ON %d, %d\n", led.read(), i ); |
| marcel1691 | 1:480364dcdacc | 47 | * led = 1; |
| marcel1691 | 1:480364dcdacc | 48 | * wait( 1.0f ); |
| marcel1691 | 1:480364dcdacc | 49 | * |
| marcel1691 | 1:480364dcdacc | 50 | * oled.cursor( 2, 0 ); |
| marcel1691 | 1:480364dcdacc | 51 | * oled.printf( "OFF %d, %d\n", led.read(), i ); |
| marcel1691 | 1:480364dcdacc | 52 | * led = 0; |
| marcel1691 | 1:480364dcdacc | 53 | * i++; |
| marcel1691 | 1:480364dcdacc | 54 | * wait( 1.0f ); |
| marcel1691 | 1:480364dcdacc | 55 | * } |
| marcel1691 | 1:480364dcdacc | 56 | * } |
| marcel1691 | 1:480364dcdacc | 57 | * @endcode |
| marcel1691 | 1:480364dcdacc | 58 | */ |
| marcel1691 | 1:480364dcdacc | 59 | |
| marcel1691 | 1:480364dcdacc | 60 | class OLEDDisplay |
| marcel1691 | 1:480364dcdacc | 61 | { |
| marcel1691 | 1:480364dcdacc | 62 | public: |
| marcel1691 | 1:480364dcdacc | 63 | OLEDDisplay( PinName rst = D9, PinName sca = D14, PinName scl = D15, uint8_t addr = 0x78 ) : i2c( sca, scl ), oled( i2c, rst, addr ) |
| marcel1691 | 1:480364dcdacc | 64 | { |
| marcel1691 | 1:480364dcdacc | 65 | } |
| marcel1691 | 1:480364dcdacc | 66 | |
| marcel1691 | 1:480364dcdacc | 67 | /** clear Display */ |
| marcel1691 | 1:480364dcdacc | 68 | void clear() |
| marcel1691 | 1:480364dcdacc | 69 | { |
| marcel1691 | 1:480364dcdacc | 70 | oled.clearDisplay(); |
| marcel1691 | 1:480364dcdacc | 71 | oled.setTextCursor( 0, 0 ); |
| marcel1691 | 1:480364dcdacc | 72 | |
| marcel1691 | 1:480364dcdacc | 73 | } |
| marcel1691 | 1:480364dcdacc | 74 | /** Set the display rotation, 1 = down, 2 = up, 3 = left, or 4 = right*/ |
| marcel1691 | 1:480364dcdacc | 75 | void setRotation(uint8_t r) |
| marcel1691 | 1:480364dcdacc | 76 | { |
| marcel1691 | 1:480364dcdacc | 77 | oled.setRotation( r ); |
| marcel1691 | 1:480364dcdacc | 78 | } |
| marcel1691 | 1:480364dcdacc | 79 | |
| marcel1691 | 1:480364dcdacc | 80 | /** printf formatted with display */ |
| marcel1691 | 1:480364dcdacc | 81 | void printf( const char *format, ... ) |
| marcel1691 | 1:480364dcdacc | 82 | { |
| marcel1691 | 1:480364dcdacc | 83 | static char buffer[128]; |
| marcel1691 | 1:480364dcdacc | 84 | |
| marcel1691 | 1:480364dcdacc | 85 | va_list args; |
| marcel1691 | 1:480364dcdacc | 86 | va_start(args, format); |
| marcel1691 | 1:480364dcdacc | 87 | vsprintf(buffer, format, args); |
| marcel1691 | 1:480364dcdacc | 88 | va_end(args); |
| marcel1691 | 1:480364dcdacc | 89 | |
| marcel1691 | 1:480364dcdacc | 90 | oled.printf( buffer ); |
| marcel1691 | 1:480364dcdacc | 91 | oled.display(); |
| marcel1691 | 1:480364dcdacc | 92 | } |
| marcel1691 | 1:480364dcdacc | 93 | |
| marcel1691 | 1:480364dcdacc | 94 | /// Set the text cursor location, based on the size of the text |
| marcel1691 | 1:480364dcdacc | 95 | void cursor( int16_t y, int16_t x ) |
| marcel1691 | 1:480364dcdacc | 96 | { |
| marcel1691 | 1:480364dcdacc | 97 | oled.setTextCursor( x * 6 , y * 8 ); |
| marcel1691 | 1:480364dcdacc | 98 | } |
| marcel1691 | 1:480364dcdacc | 99 | |
| marcel1691 | 1:480364dcdacc | 100 | |
| marcel1691 | 1:480364dcdacc | 101 | private: |
| marcel1691 | 1:480364dcdacc | 102 | I2C i2c; |
| marcel1691 | 1:480364dcdacc | 103 | Adafruit_SSD1306_I2c oled; |
| marcel1691 | 1:480364dcdacc | 104 | }; |
| marcel1691 | 1:480364dcdacc | 105 | |
| marcel1691 | 1:480364dcdacc | 106 | #endif // OLED_DISPLAY |