|
| 1 | +/* |
| 2 | + * Copyright (c) 2023, Raphael Lehmann |
| 3 | + * |
| 4 | + * This file is part of the modm project. |
| 5 | + * |
| 6 | + * This Source Code Form is subject to the terms of the Mozilla Public |
| 7 | + * License, v. 2.0. If a copy of the MPL was not distributed with this |
| 8 | + * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 9 | + */ |
| 10 | + |
| 11 | +#include <modm/board.hpp> |
| 12 | +#include <modm/driver/display/sh1106_i2c.hpp> |
| 13 | +// #include <modm/driver/display/ssd1306_i2c.hpp> |
| 14 | + |
| 15 | +/// SH1106 display in I2C mode |
| 16 | +using MyI2cMaster = modm::platform::I2cMaster1; |
| 17 | +using Scl = Board::D15; |
| 18 | +using Sda = Board::D14; |
| 19 | + |
| 20 | +using Display = modm::Sh1106I2c<MyI2cMaster>; |
| 21 | +// using Display = modm::Ssd1306<MyI2cMaster>; |
| 22 | + |
| 23 | +Display display; |
| 24 | + |
| 25 | +int |
| 26 | +main() |
| 27 | +{ |
| 28 | + Board::initialize(); |
| 29 | + |
| 30 | + modm::delay(100ms); |
| 31 | + |
| 32 | + MyI2cMaster::connect<Sda::Sda, Scl::Scl>(); |
| 33 | + // Use 20kHz I2C and internal pull-ups, works without external pull-ups |
| 34 | + // if the jumper wires are short enought |
| 35 | + MyI2cMaster::connect<Sda::Sda, Scl::Scl>(MyI2cMaster::PullUps::Internal); |
| 36 | + |
| 37 | + modm::delay(100ms); |
| 38 | + |
| 39 | + RF_CALL_BLOCKING(display.initialize()); |
| 40 | + RF_CALL_BLOCKING(display.setOrientation(modm::glcd::Orientation::Landscape0)); |
| 41 | + RF_CALL_BLOCKING(display.setDisplayMode(Display::DisplayMode::Inverted)); |
| 42 | + RF_CALL_BLOCKING(display.setContrast(80)); |
| 43 | + |
| 44 | + display.setFont(modm::font::Assertion); |
| 45 | + |
| 46 | + modm::ShortPeriodicTimer timer(333ms); |
| 47 | + uint16_t counter(0); |
| 48 | + |
| 49 | + while (true) |
| 50 | + { |
| 51 | + if (timer.execute()) |
| 52 | + { |
| 53 | + display.clear(); |
| 54 | + display.setCursor(1, 1); |
| 55 | + display << "Hello World!"; |
| 56 | + display.setCursor(1, 17); |
| 57 | + display << counter++; |
| 58 | + display.setCursor(1, 33); |
| 59 | + display << "Line 3"; |
| 60 | + display.setCursor(1, 49); |
| 61 | + display << "Line 4"; |
| 62 | + |
| 63 | + display.update(); |
| 64 | + } |
| 65 | + } |
| 66 | + |
| 67 | + return 0; |
| 68 | +} |
0 commit comments