mirror of
https://github.com/geekammo/MicroView-Arduino-Library.git
synced 2026-02-20 11:31:24 +01:00
Compare commits
18 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c86b454924 | ||
|
|
ad46711f11 | ||
|
|
34de240739 | ||
|
|
6333d7c561 | ||
|
|
a5ed62704a | ||
|
|
9573e7d6cc | ||
|
|
86784fe2a4 | ||
|
|
cf97ba6c23 | ||
|
|
dfe47be3c8 | ||
|
|
db155041ff | ||
|
|
ba0b779740 | ||
|
|
8eab806dec | ||
|
|
9873dc728a | ||
|
|
72fdeeb77b | ||
|
|
4a8583e2a6 | ||
|
|
b0e4a9600f | ||
|
|
e203d3b7cd | ||
|
|
b91baf75f8 |
@@ -591,7 +591,6 @@ void MicroView::circle(uint8_t x0, uint8_t y0, uint8_t radius, uint8_t color, ui
|
||||
pixel(x0 - y, y0 + x, color, mode);
|
||||
pixel(x0 + y, y0 - x, color, mode);
|
||||
pixel(x0 - y, y0 - x, color, mode);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -608,38 +607,44 @@ void MicroView::circleFill(uint8_t x0, uint8_t y0, uint8_t radius) {
|
||||
Draw filled circle with radius using color and mode at x,y of the screen buffer.
|
||||
*/
|
||||
void MicroView::circleFill(uint8_t x0, uint8_t y0, uint8_t radius, uint8_t color, uint8_t mode) {
|
||||
// TODO - - find a way to check for no overlapping of pixels so that XOR draw mode will work perfectly
|
||||
int8_t f = 1 - radius;
|
||||
int8_t ddF_x = 1;
|
||||
int8_t ddF_y = -2 * radius;
|
||||
int8_t x = 0;
|
||||
int8_t y = radius;
|
||||
|
||||
// Temporary disable fill circle for XOR mode.
|
||||
if (mode==XOR) return;
|
||||
|
||||
for (uint8_t i=y0-radius; i<=y0+radius; i++) {
|
||||
pixel(x0, i, color, mode);
|
||||
// Don't bother trying to draw something totally offscreen
|
||||
if (x0 - radius >= LCDWIDTH || y0 - radius >= LCDHEIGHT) {
|
||||
return;
|
||||
}
|
||||
|
||||
while (x<y) {
|
||||
if (f >= 0) {
|
||||
y--;
|
||||
ddF_y += 2;
|
||||
f += ddF_y;
|
||||
}
|
||||
x++;
|
||||
ddF_x += 2;
|
||||
f += ddF_x;
|
||||
// High-level algorithm overview:
|
||||
// Scan horizontally from left to right, then top to bottom, checking if each pixel
|
||||
// is within the circle. We use uint16_t's because even the small screen squares beyond 8 bits.
|
||||
uint16_t radiusSq = radius * radius;
|
||||
|
||||
for (uint8_t i=y0-y; i<=y0+y; i++) {
|
||||
pixel(x0+x, i, color, mode);
|
||||
pixel(x0-x, i, color, mode);
|
||||
}
|
||||
for (uint8_t i=y0-x; i<=y0+x; i++) {
|
||||
pixel(x0+y, i, color, mode);
|
||||
pixel(x0-y, i, color, mode);
|
||||
}
|
||||
// Optimization: define the start and end onscreen
|
||||
uint16_t xStart = max(0, x0-radius);
|
||||
uint16_t xEnd = min(LCDWIDTH-1, x0+radius);
|
||||
uint16_t yStart = max(0, y0-radius);
|
||||
uint16_t yEnd = min(LCDHEIGHT-1, y0+radius);
|
||||
|
||||
// scan horizontally...
|
||||
for (uint16_t x = xStart; x <= xEnd; ++x) {
|
||||
// Optimization: Record where if we have intersected the circle on this vertical
|
||||
// scan. Once we have intersected, then don't intersect anymore, don't bother
|
||||
// drawing; we've exited the circle.
|
||||
bool intersected = false;
|
||||
|
||||
// Optimization: relative x squared only changes with the outer loop/the horizontal scan.
|
||||
int16_t rx2 = (x-x0) * (x-x0);
|
||||
|
||||
// Scan vertically...
|
||||
for (uint16_t y = yStart; y <= yEnd; ++y) {
|
||||
int16_t ry2 = (y-y0) * (y-y0);
|
||||
if (rx2 + ry2 <= radiusSq) {
|
||||
pixel(x, y, color, mode);
|
||||
intersected = true;
|
||||
}
|
||||
else if (intersected) {
|
||||
// We've left the circle. Move on to the next horizontal scan line.
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -904,6 +909,14 @@ void MicroView::flipHorizontal(boolean flip) {
|
||||
}
|
||||
}
|
||||
|
||||
/** \brief Get pointer to screen buffer
|
||||
|
||||
Return a pointer to the start of the RAM screen buffer for direct access.
|
||||
*/
|
||||
uint8_t *MicroView::getScreenBuffer(void) {
|
||||
return screenmemory;
|
||||
}
|
||||
|
||||
/** \brief Parse command.
|
||||
|
||||
Command stored in serCmd array will be parsed to performed draw functions.
|
||||
|
||||
@@ -192,6 +192,7 @@ public:
|
||||
uint8_t getLCDHeight(void);
|
||||
void setColor(uint8_t color);
|
||||
void setDrawMode(uint8_t mode);
|
||||
uint8_t *getScreenBuffer(void);
|
||||
|
||||
// Font functions
|
||||
uint8_t getFontWidth(void);
|
||||
|
||||
@@ -92,6 +92,12 @@ void loop() {
|
||||
</code></pre>
|
||||
|
||||
## History
|
||||
**v1.20b: 27th August 2014 by Scott Allen, Emil Ong**
|
||||
* added Flashing Heart Example - JP
|
||||
* added getScreenBuffer() for access to screen RAM - Scott
|
||||
* added keywords for existing functions - Scott
|
||||
* fixed circleFill() - Emil
|
||||
|
||||
**v1.19b: 19th August 2014 by Scott Allen**
|
||||
* added uView.scrollLeft() function
|
||||
* simplified Silder Widget drawFace() function
|
||||
|
||||
101
examples/MicroViewFlashingHeart/MicroViewFlashingHeart.ino
Normal file
101
examples/MicroViewFlashingHeart/MicroViewFlashingHeart.ino
Normal file
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
MicroView Arduino Flashing Heart Demo
|
||||
Copyright (C) 2014 GeekAmmo
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <MicroView.h>
|
||||
|
||||
const unsigned char logo [] = {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xFF, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F,
|
||||
0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0xFF, 0xE0, 0xE0, 0xE0,
|
||||
0xE0, 0xE0, 0xE0, 0xFF, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F,
|
||||
0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0xFF, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x0F, 0x0F,
|
||||
0x0F, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x80, 0x80, 0x80, 0x80, 0x80,
|
||||
0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80,
|
||||
0x80, 0x80, 0x80, 0x80, 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F,
|
||||
0xFF, 0xFF, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xFF, 0xFF,
|
||||
0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0xFF, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0x00, 0x00,
|
||||
0x00, 0x00, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xFF, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0xFF, 0xFF, 0xFE, 0xFE,
|
||||
0xFE, 0xFE, 0xFF, 0xFF, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
};
|
||||
|
||||
|
||||
const unsigned char logo2 [] = {
|
||||
0x00, 0x00, 0x00, 0x00, 0xC0, 0xE0, 0xE0, 0xE0, 0xE0, 0xFF, 0xFF, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F,
|
||||
0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xE0, 0xE0, 0xE0,
|
||||
0xE0, 0xE0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xF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0F,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
};
|
||||
|
||||
|
||||
void setup() {
|
||||
uView.begin();
|
||||
uView.clear(PAGE);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
unsigned char i,j;
|
||||
for (i=0; i<6; i++) {
|
||||
uView.setPageAddress(i);
|
||||
uView.setColumnAddress(0);
|
||||
for (j=0;j<0x40;j++) {
|
||||
uView.data(logo[i*0x40+j]);
|
||||
}
|
||||
}
|
||||
|
||||
delay(800);
|
||||
|
||||
for (i=0; i<6; i++) {
|
||||
uView.setPageAddress(i);
|
||||
uView.setColumnAddress(0);
|
||||
for (j=0;j<0x40;j++) {
|
||||
uView.data(logo2[i*0x40+j]);
|
||||
}
|
||||
}
|
||||
delay(150);
|
||||
}
|
||||
@@ -17,7 +17,6 @@ MicroViewGauge KEYWORD1
|
||||
#######################################
|
||||
|
||||
begin KEYWORD2
|
||||
invert KEYWORD2
|
||||
clear KEYWORD2
|
||||
invert KEYWORD2
|
||||
contrast KEYWORD2
|
||||
@@ -50,6 +49,10 @@ scrollVertLeft KEYWORD2
|
||||
scrollStop KEYWORD2
|
||||
flipVertical KEYWORD2
|
||||
flipHorizontal KEYWORD2
|
||||
setColumnAddress KEYWORD2
|
||||
setPageAddress KEYWORD2
|
||||
data KEYWORD2
|
||||
getScreenBuffer KEYWORD2
|
||||
|
||||
getX KEYWORD2
|
||||
getY KEYWORD2
|
||||
|
||||
Reference in New Issue
Block a user