|
| 1 | +/* |
| 2 | + SFE_MicroOLED Library Demo |
| 3 | + Paul Clark @ SparkFun Electronics |
| 4 | + Original Creation Date: April 3rd, 2021 |
| 5 | +
|
| 6 | + This sketch demonstrates how to use the Large Letter 31x48 font. |
| 7 | + This font is disabled by default. To enable it, you need to edit |
| 8 | + SFE_MicroOLED.cpp and uncomment the line which says: |
| 9 | + #include "util/fontlargeletter31x48.h" |
| 10 | +
|
| 11 | + Hardware Connections: |
| 12 | + This example assumes you are using Qwiic. See the SPI examples for |
| 13 | + a detailed breakdown of connection info. |
| 14 | +
|
| 15 | + Want to support open source hardware? Buy a board from SparkFun! |
| 16 | + https://www.sparkfun.com/products/13003 |
| 17 | + https://www.sparkfun.com/products/14532 |
| 18 | +
|
| 19 | + This code is beerware; if you see me (or any other SparkFun employee) at the |
| 20 | + local, and you've found our code helpful, please buy us a round! |
| 21 | + |
| 22 | + Distributed as-is; no warranty is given. |
| 23 | +*/ |
| 24 | + |
| 25 | +#include <Wire.h> |
| 26 | +#include <SFE_MicroOLED.h> //Click here to get the library: http://librarymanager/All#SparkFun_Micro_OLED |
| 27 | + |
| 28 | +#define PIN_RESET 9 |
| 29 | + |
| 30 | +// From version v1.3, we can instantiate oled like this (but only for I2C) |
| 31 | +MicroOLED oled(PIN_RESET); |
| 32 | + |
| 33 | +void setup() |
| 34 | +{ |
| 35 | + Serial.begin(115200); // Begin the Serial port |
| 36 | + Serial.println(F("SparkFun MicroOLED Example")); |
| 37 | + |
| 38 | + delay(100); |
| 39 | + Wire.begin(); |
| 40 | + |
| 41 | + // This is the new way of initializing the OLED. |
| 42 | + // We can pass a different I2C address and TwoWire port |
| 43 | + // If 0x3D does not work, try 0x3C |
| 44 | + oled.begin(0x3C, Wire); // Initialize the OLED |
| 45 | + |
| 46 | + // Print the total number of fonts loaded into memory |
| 47 | + Serial.print(F("There are ")); |
| 48 | + Serial.print(oled.getTotalFonts()); |
| 49 | + Serial.println(F(" fonts available")); |
| 50 | + |
| 51 | + oled.clear(ALL); // Clear the display's internal memory |
| 52 | + oled.display(); // Display what's in the buffer (splashscreen) |
| 53 | + |
| 54 | + delay(1000); // Delay 1000 ms |
| 55 | + |
| 56 | + oled.clear(PAGE); // Clear the buffer. |
| 57 | + |
| 58 | + if (oled.setFontType(4) == 0) // Set font to type 4 (fontlargeletter31x48) |
| 59 | + { |
| 60 | + Serial.println(F("Could not enable font 4 (fontlargeletter31x48)!")); |
| 61 | + Serial.println(F("Have you uncommented #include \"util/fontlargeletter31x48.h\" in SFE_MicroOLED.cpp?")); |
| 62 | + Serial.println(F("Freezing...")); |
| 63 | + while (1) |
| 64 | + ; // Do nothing more |
| 65 | + } |
| 66 | +} |
| 67 | + |
| 68 | +void loop() |
| 69 | +{ |
| 70 | + // Demonstrate font 4 |
| 71 | + // There are 58 possible characters in the font 4 type: A - z |
| 72 | + // Lets run through all of them and print them out! |
| 73 | + for (int i = 'A'; i <= 'z'; i += 2) |
| 74 | + { |
| 75 | + oled.clear(PAGE); // Clear the screen |
| 76 | + |
| 77 | + oled.setCursor(0, 0); // Set cursor to top-left |
| 78 | + |
| 79 | + oled.write(i); // Write a byte out as a character |
| 80 | + oled.write(i+1); // Write the next byte out as a character |
| 81 | + oled.display(); // Draw on the screen |
| 82 | + |
| 83 | + delay(500); // Delay 500 ms |
| 84 | + } |
| 85 | +} |
0 commit comments