Skip to content

Commit df490db

Browse files
author
Kirk
committed
cleanup and rename of bitmap example
1 parent 175c776 commit df490db

File tree

2 files changed

+176
-117
lines changed

2 files changed

+176
-117
lines changed
Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
2+
// Example-03_Bitmap.ino
3+
//
4+
// This is a library written for SparkFun Qwiic OLED boards that use the SSD1306.
5+
//
6+
// SparkFun sells these at its website: www.sparkfun.com
7+
//
8+
// Do you like this library? Help support SparkFun. Buy a board!
9+
//
10+
// Micro OLED https://www.sparkfun.com/products/14532
11+
// Transparent OLED https://www.sparkfun.com/products/15173
12+
// "Narrow" OLED https://www.sparkfun.com/products/17153
13+
//
14+
//
15+
// Written by Nathan Seidle @ SparkFun Electronics
16+
// Original Creation Date: November 15, 2020
17+
//
18+
// This library configures and draws graphics to OLED boards that use the
19+
// SSD1306 display hardware. The library only supports I2C.
20+
//
21+
// Repository:
22+
// https://github.com/sparkfun/SparkFun_Qwiic_OLED_Arduino_Library
23+
//
24+
// Documentation:
25+
// https://sparkfun.github.io/SparkFun_Qwiic_OLED_Arduino_Library/
26+
//
27+
//
28+
// SparkFun code, firmware, and software is released under the MIT License(http://opensource.org/licenses/MIT).
29+
//
30+
// SPDX-License-Identifier: MIT
31+
//
32+
// The MIT License (MIT)
33+
//
34+
// Copyright (c) 2022 SparkFun Electronics
35+
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
36+
// associated documentation files (the "Software"), to deal in the Software without restriction,
37+
// including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
38+
// and/or sell copies of the Software, and to permit persons to whom the Software is furnished to
39+
// do so, subject to the following conditions:
40+
// The above copyright notice and this permission notice shall be included in all copies or substantial
41+
// portions of the Software.
42+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
43+
// NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
44+
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
45+
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
46+
// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
47+
//
48+
//////////////////////////////////////////////////////////////////////////////////////////
49+
// Example 3 for the SparkFun Qwiic OLED Arduino Library
50+
//
51+
// >> Overview <<
52+
//
53+
// This demo shows how to write a simple bitmap to an OLED screen
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+
92+
// Let's draw a truck - use our built in bitmap
93+
#include "res/qw_bmp_truck.h"
94+
95+
96+
int width;
97+
int height;
98+
99+
// For simple frame rate calculations
100+
uint32_t draw_total_time;
101+
uint32_t n_draws;
102+
103+
void setup(){
104+
105+
delay(500); //Give display time to power on
106+
Serial.begin(115200);
107+
108+
Serial.println("\n\r-----------------------------------");
109+
110+
Serial.print("Running Test #2 on: ");
111+
Serial.println(String(deviceName));
112+
113+
if(!myOLED.begin()){
114+
115+
Serial.println("- Device Begin Failed");
116+
while(1);
117+
}
118+
119+
Serial.println("- Begin Successful");
120+
121+
// save device dims for the test routines
122+
width = myOLED.getWidth();
123+
height = myOLED.getHeight();
124+
125+
draw_total_time =0;
126+
n_draws=0;
127+
128+
// set a template for our framerate display
129+
Serial.println("- Frame Rate");
130+
}
131+
132+
int iconX = 8;
133+
int iconXChangeAmount = 1;
134+
int iconY = 8;
135+
int iconYChangeAmount = 1;
136+
137+
void loop(){
138+
139+
// Calculate draw time...
140+
uint32_t milStart = millis();
141+
142+
myOLED.bitmap(iconX, iconY, QW_BMP_TRUCK);
143+
myOLED.display();
144+
145+
//Move the icon
146+
iconX += iconXChangeAmount;
147+
iconY += iconYChangeAmount;
148+
149+
if(iconX + QW_BMP_TRUCK.width >= width)
150+
iconXChangeAmount *= -1; //Change direction
151+
152+
if(iconX == 0)
153+
iconXChangeAmount *= -1; //Change direction
154+
155+
156+
if(iconY + QW_BMP_TRUCK.height >= height)
157+
iconYChangeAmount *= -1; //Change direction
158+
159+
if(iconY == 0)
160+
iconYChangeAmount *= -1; //Change direction
161+
162+
draw_total_time += millis() - milStart;
163+
n_draws++;
164+
165+
// output framerate?
166+
if(n_draws % 120 == 0){
167+
168+
Serial.println(((float)draw_total_time)/n_draws);
169+
170+
if(n_draws > 1000){ // reset after a bit...
171+
n_draws = 0;
172+
draw_total_time=0;
173+
}
174+
}
175+
}
176+

examples/Example6_DrawIcon/Example6_DrawIcon.ino

Lines changed: 0 additions & 117 deletions
This file was deleted.

0 commit comments

Comments
 (0)