|
| 1 | +// |
| 2 | +// Simple demo sketch to show how to use the new |
| 3 | +// C++ class which wraps the OneBitDisplay C API |
| 4 | +// This class was modeled after the Adafruit GFX API |
| 5 | +// to make it easier to port code, yet still retains |
| 6 | +// the unique features of OBD |
| 7 | +// |
| 8 | +// Written by Larry Bank |
| 9 | +// project started April 24, 2022 |
| 10 | +// |
| 11 | +#include <OneBitDisplay.h> |
| 12 | +ONE_BIT_DISPLAY tft; // static class instantiation |
| 13 | + |
| 14 | +void setup() |
| 15 | +{ |
| 16 | + int i; |
| 17 | + // The I2Cbegin() method needs a minimum of the type of OLED/LCD being used |
| 18 | + // Optional parameters are for the I2C address (auto discovered if not specified) |
| 19 | + // and the I2C bus speed (defaults to 400Kbs) |
| 20 | + // The Arduino default I2C pins are used here (works on many setups) |
| 21 | + // If you need to specify them, use the setI2CPins() method |
| 22 | + tft.I2Cbegin(OLED_64x128); |
| 23 | + // |
| 24 | + // Here we're asking the library to allocate the backing buffer |
| 25 | + // If successful, the library will change the render flag to "RAM only" so that |
| 26 | + // all drawing occurs only to the internal buffer, and display() must be called |
| 27 | + // to see the changes. Without a backing buffer, the API will try to draw all |
| 28 | + // output directly to the display instead. |
| 29 | + // |
| 30 | + if (!tft.allocBuffer()) { |
| 31 | + tft.print("Alloc failed"); |
| 32 | + } |
| 33 | +// tft.setRotation(3); // optionally rotate in 90 degree increments - only supports 0/180 without a RAM backing buffer |
| 34 | + tft.fillScreen(OLED_BLACK); |
| 35 | + tft.setScroll(true); // enable text printing to scroll the display buffer a line at a time |
| 36 | + tft.setFont(FONT_12x16); // Use the 6x8 (stretched+smoothed) font |
| 37 | + i = 0; |
| 38 | + while (1) { |
| 39 | + tft.print("Count = "); |
| 40 | + tft.println(i++, DEC); // this will keep the last line blank because it immediately scrolls up |
| 41 | + tft.display(); // copy the RAM buffer to the physical display |
| 42 | + delay(250); // slow it down a bit |
| 43 | + } |
| 44 | +} |
| 45 | + |
| 46 | +void loop() { |
| 47 | +// nothing going on here |
| 48 | +} |
0 commit comments