|
| 1 | +// Example-02_Shapes.ino |
| 2 | +// |
| 3 | +// This is a library written for SparkFun Qwiic OLED boards that use the SSD1306. |
| 4 | +// |
| 5 | +// SparkFun sells these at its website: www.sparkfun.com |
| 6 | +// |
| 7 | +// Do you like this library? Help support SparkFun. Buy a board! |
| 8 | +// |
| 9 | +// Micro OLED https://www.sparkfun.com/products/14532 |
| 10 | +// Transparent OLED https://www.sparkfun.com/products/15173 |
| 11 | +// "Narrow" OLED https://www.sparkfun.com/products/17153 |
| 12 | +// |
| 13 | +// |
| 14 | +// Written by Kirk Benell @ SparkFun Electronics, March 2022 |
| 15 | +// |
| 16 | +// This library configures and draws graphics to OLED boards that use the |
| 17 | +// SSD1306 display hardware. The library only supports I2C. |
| 18 | +// |
| 19 | +// Repository: |
| 20 | +// https://github.com/sparkfun/SparkFun_Qwiic_OLED_Arduino_Library |
| 21 | +// |
| 22 | +// Documentation: |
| 23 | +// https://sparkfun.github.io/SparkFun_Qwiic_OLED_Arduino_Library/ |
| 24 | +// |
| 25 | +// |
| 26 | +// SparkFun code, firmware, and software is released under the MIT License(http://opensource.org/licenses/MIT). |
| 27 | +// |
| 28 | +// SPDX-License-Identifier: MIT |
| 29 | +// |
| 30 | +// The MIT License (MIT) |
| 31 | +// |
| 32 | +// Copyright (c) 2022 SparkFun Electronics |
| 33 | +// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and |
| 34 | +// associated documentation files (the "Software"), to deal in the Software without restriction, |
| 35 | +// including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 36 | +// and/or sell copies of the Software, and to permit persons to whom the Software is furnished to |
| 37 | +// do so, subject to the following conditions: |
| 38 | +// The above copyright notice and this permission notice shall be included in all copies or substantial |
| 39 | +// portions of the Software. |
| 40 | +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT |
| 41 | +// NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 42 | +// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
| 43 | +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
| 44 | +// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 45 | +// |
| 46 | +////////////////////////////////////////////////////////////////////////////////////////// |
| 47 | +// Example 5 for the SparkFun Qwiic OLED Arduino Library |
| 48 | +// |
| 49 | +// >> Overview << |
| 50 | +// |
| 51 | +// This demo shows the various display options - scrolling, flipping, invert. |
| 52 | +// |
| 53 | +// NOTE: Scrolling isn't supported on the Transparent OLED |
| 54 | +// |
| 55 | +////////////////////////////////////////////////////////////////////////////////////////// |
| 56 | +// |
| 57 | +// >>> SELECT THE CONNECTED DEVICE FOR THIS EXAMPLE <<< |
| 58 | +// |
| 59 | +// The Library supports three different types of SparkFun boards. The demo uses the following |
| 60 | +// defines to determine which device is being used. Uncomment the device being used for this demo. |
| 61 | +// |
| 62 | +// The default is Micro OLED |
| 63 | + |
| 64 | +#define MICRO |
| 65 | +//#define NARROW |
| 66 | +//#define TRANSPARENT |
| 67 | + |
| 68 | +////////////////////////////////////////////////////////////////////////////////////////// |
| 69 | + |
| 70 | +#include <stdint.h> |
| 71 | + |
| 72 | +// Include the SparkFun qwiic OLED Library |
| 73 | +#include <SparkFun_Qwiic_OLED.h> |
| 74 | + |
| 75 | +// What device is being used in this demo |
| 76 | + |
| 77 | +#if defined(TRANSPARENT) |
| 78 | +QwiicTransparentOLED myOLED; |
| 79 | +const char * deviceName = "Transparent OLED"; |
| 80 | + |
| 81 | +#elif defined(NARROW) |
| 82 | +QwiicNarrowOLED myOLED; |
| 83 | +const char * deviceName = "Narrow OLED"; |
| 84 | + |
| 85 | +#else |
| 86 | +QwiicMicroOLED myOLED; |
| 87 | +const char * deviceName = "Micro OLED"; |
| 88 | + |
| 89 | +#endif |
| 90 | + |
| 91 | +int yoffset; |
| 92 | + |
| 93 | +//////////////////////////////////////////////////////////////////////////////////////////////// |
| 94 | +// setup() |
| 95 | +// |
| 96 | +// Standard Arduino setup routine |
| 97 | + |
| 98 | +void setup() |
| 99 | +{ |
| 100 | + delay(500); //Give display time to power on |
| 101 | + Serial.begin(115200); |
| 102 | + |
| 103 | + Serial.println("\n\r-----------------------------------"); |
| 104 | + |
| 105 | + Serial.print("Running Test #5 on: "); |
| 106 | + Serial.println(String(deviceName)); |
| 107 | + |
| 108 | + if(!myOLED.begin()){ |
| 109 | + |
| 110 | + Serial.println("- Device Begin Failed"); |
| 111 | + while(1); |
| 112 | + } |
| 113 | + |
| 114 | + yoffset = (myOLED.getHeight() - myOLED.getFont()->height)/2; |
| 115 | + |
| 116 | + delay(1000); |
| 117 | +} |
| 118 | + |
| 119 | +// Our testing functions |
| 120 | + |
| 121 | +void scroll_right(void){ |
| 122 | + |
| 123 | + myOLED.scrollStop(); |
| 124 | + myOLED.scrollRight(0, 7, SCROLL_INTERVAL_2_FRAMES); |
| 125 | +} |
| 126 | + |
| 127 | +void scroll_right_vert(void){ |
| 128 | + myOLED.scrollStop(); |
| 129 | + myOLED.scrollVertRight(0, 7, SCROLL_INTERVAL_3_FRAMES); |
| 130 | +} |
| 131 | + |
| 132 | +void scroll_left(void){ |
| 133 | + myOLED.scrollStop(); |
| 134 | + myOLED.scrollLeft(0, 7, SCROLL_INTERVAL_4_FRAMES); |
| 135 | +} |
| 136 | + |
| 137 | +void scroll_left_vert(void){ |
| 138 | + myOLED.scrollStop(); |
| 139 | + myOLED.scrollVertLeft(0, 7, SCROLL_INTERVAL_5_FRAMES); |
| 140 | +} |
| 141 | + |
| 142 | +void scroll_stop(void){ |
| 143 | + myOLED.scrollStop(); |
| 144 | +} |
| 145 | + |
| 146 | +void flip_horz(void){ |
| 147 | + |
| 148 | + for(int i=0; i < 6; i++){ |
| 149 | + myOLED.flipHorizontal(!(i & 0x01)); |
| 150 | + delay(800); |
| 151 | + } |
| 152 | +} |
| 153 | + |
| 154 | +void flip_vert(void){ |
| 155 | + for(int i=0; i < 6; i++){ |
| 156 | + myOLED.flipVertical(!(i & 0x01)); |
| 157 | + delay(800); |
| 158 | + } |
| 159 | +} |
| 160 | + |
| 161 | +void invert(void){ |
| 162 | + for(int i=0; i < 6; i++){ |
| 163 | + myOLED.invert(!(i & 0x01)); |
| 164 | + delay(800); |
| 165 | + } |
| 166 | +} |
| 167 | + |
| 168 | +//////////////////////////////////////////////////////////////////////////////////////////////// |
| 169 | +// |
| 170 | +// Use an array of testing functions, with a title, to run the tests |
| 171 | + |
| 172 | +typedef void (*testFn)(void); |
| 173 | +typedef struct _testRoutines{ |
| 174 | + void (*testFn)(void); |
| 175 | + const char *title; |
| 176 | +}testRoutine; |
| 177 | + |
| 178 | +static const testRoutine testFunctions[] = { |
| 179 | + {scroll_right, "Right>"}, |
| 180 | + {scroll_right_vert, "^Right-Up>"}, |
| 181 | + {scroll_left, "<Left"}, |
| 182 | + {scroll_left_vert, "<Left-Up^"}, |
| 183 | + {scroll_stop, "<STOP>"}, |
| 184 | + {flip_horz, "-Flip-Horz-"}, |
| 185 | + {flip_vert, "|Flip-Vert|"}, |
| 186 | + {invert, "**INVERT**"} |
| 187 | +}; |
| 188 | + |
| 189 | +//////////////////////////////////////////////////////////////////////////////////////////////// |
| 190 | +// loop() |
| 191 | +// |
| 192 | +// Standard Arduino loop routine |
| 193 | +void loop() |
| 194 | +{ |
| 195 | + |
| 196 | + // loop over the test table entries, write title and run test. |
| 197 | + for(uint8_t i=0; i < sizeof(testFunctions)/sizeof(testFunctions[0]); i++){ |
| 198 | + |
| 199 | + |
| 200 | + if(testFunctions[i].title){ |
| 201 | + myOLED.erase(); |
| 202 | + myOLED.text(3, yoffset, testFunctions[i].title); |
| 203 | + myOLED.display(); |
| 204 | + } |
| 205 | + testFunctions[i].testFn(); // run test |
| 206 | + |
| 207 | + delay(3000); |
| 208 | + } |
| 209 | + |
| 210 | +} |
0 commit comments