mirror of
https://github.com/geekammo/MicroView-Arduino-Library.git
synced 2026-02-22 12:31:22 +01:00
* changed MICROVIEW class name to MicroView
* created MICROVIEWWIDGET class * added routines to draw widget * added slider widget * merged MicroViewWidget into MicroView * merged SPI.h into MicroView
This commit is contained in:
281
MicroView.cpp
281
MicroView.cpp
@@ -1,6 +1,10 @@
|
||||
#include <avr/pgmspace.h>
|
||||
#include <MicroView.h>
|
||||
#include <SPI.h>
|
||||
#include <MicroView.h>
|
||||
|
||||
// This fixed ugly GCC warning "only initialized variables can be placed into program memory area"
|
||||
#undef PROGMEM
|
||||
#define PROGMEM __attribute__((section(".progmem.data")))
|
||||
|
||||
// Add header of the fonts here. Remove as many as possible to get conserve FLASH memory.
|
||||
#include <font5x7.h>
|
||||
@@ -15,7 +19,16 @@
|
||||
#define TOTALFONTS 7
|
||||
|
||||
// Add the font name as declared in the header file. Remove as many as possible to get conserve FLASH memory.
|
||||
const unsigned char *MICROVIEW::fontsPointer[]={font5x7,font8x16,sevensegment,fontlargenumber, space01,space02,space03};
|
||||
const unsigned char *MicroView::fontsPointer[]={
|
||||
font5x7
|
||||
,font8x16
|
||||
,sevensegment
|
||||
,fontlargenumber
|
||||
,space01
|
||||
,space02
|
||||
,space03
|
||||
|
||||
};
|
||||
|
||||
// TODO - Need to be able to let user add custom fonts from outside of the library
|
||||
// TODO - getTotalFonts(), addFont() return font number, removeFont()
|
||||
@@ -67,7 +80,7 @@ static uint8_t screenmemory [] = {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
};
|
||||
|
||||
void MICROVIEW::begin() {
|
||||
void MicroView::begin() {
|
||||
// default 5x7 font
|
||||
setFontType(0);
|
||||
setColor(WHITE);
|
||||
@@ -79,15 +92,15 @@ void MICROVIEW::begin() {
|
||||
pinMode(SCK, OUTPUT);
|
||||
pinMode(DC, OUTPUT);
|
||||
pinMode(RESET, OUTPUT);
|
||||
pinMode(CS, OUTPUT);
|
||||
digitalWrite(CS, HIGH);
|
||||
pinMode(SS, OUTPUT);
|
||||
digitalWrite(SS, HIGH);
|
||||
|
||||
sckport = portOutputRegister(digitalPinToPort(SCK));
|
||||
sckpinmask = digitalPinToBitMask(SCK);
|
||||
mosiport = portOutputRegister(digitalPinToPort(MOSI));
|
||||
mosipinmask = digitalPinToBitMask(MOSI);
|
||||
csport = portOutputRegister(digitalPinToPort(CS));
|
||||
cspinmask = digitalPinToBitMask(CS);
|
||||
ssport = portOutputRegister(digitalPinToPort(SS));
|
||||
sspinmask = digitalPinToBitMask(SS);
|
||||
dcport = portOutputRegister(digitalPinToPort(DC));
|
||||
dcpinmask = digitalPinToBitMask(DC);
|
||||
|
||||
@@ -98,8 +111,8 @@ void MICROVIEW::begin() {
|
||||
digitalWrite(RESET, LOW);
|
||||
|
||||
// Setup SPI frequency
|
||||
SPI.setClockDivider(SPI_CLOCK_DIV2);
|
||||
SPI.begin();
|
||||
MVSPI.setClockDivider(SPI_CLOCK_DIV2);
|
||||
MVSPI.begin();
|
||||
|
||||
// wait 10ms
|
||||
delay(10);
|
||||
@@ -146,31 +159,31 @@ void MICROVIEW::begin() {
|
||||
clear(ALL); // Erase hardware memory inside the OLED controller to avoid random data in memory.
|
||||
}
|
||||
|
||||
void MICROVIEW::command(uint8_t c) {
|
||||
void MicroView::command(uint8_t c) {
|
||||
// Hardware SPI
|
||||
*csport |= cspinmask; // CS HIGH
|
||||
*ssport |= sspinmask; // SS HIGH
|
||||
*dcport &= ~dcpinmask; // DC LOW
|
||||
*csport &= ~cspinmask; // CS LOW
|
||||
SPI.transfer(c);
|
||||
*csport |= cspinmask; // CS HIGH
|
||||
*ssport &= ~sspinmask; // SS LOW
|
||||
MVSPI.transfer(c);
|
||||
*ssport |= sspinmask; // SS HIGH
|
||||
}
|
||||
|
||||
void MICROVIEW::data(uint8_t c) {
|
||||
void MicroView::data(uint8_t c) {
|
||||
// Hardware SPI
|
||||
*csport |= cspinmask; // CS HIGH
|
||||
*ssport |= sspinmask; // SS HIGH
|
||||
*dcport |= dcpinmask; // DC HIGH
|
||||
*csport &= ~cspinmask; // CS LOW
|
||||
SPI.transfer(c);
|
||||
*csport |= cspinmask; // CS HIGH
|
||||
*ssport &= ~sspinmask; // SS LOW
|
||||
MVSPI.transfer(c);
|
||||
*ssport |= sspinmask; // SS HIGH
|
||||
}
|
||||
|
||||
void MICROVIEW::setPageAddress(uint8_t add) {
|
||||
void MicroView::setPageAddress(uint8_t add) {
|
||||
add=0xb0|add;
|
||||
command(add);
|
||||
return;
|
||||
}
|
||||
|
||||
void MICROVIEW::setColumnAddress(uint8_t add) {
|
||||
void MicroView::setColumnAddress(uint8_t add) {
|
||||
command((0x10|(add>>4))+0x02);
|
||||
command((0x0f&add));
|
||||
return;
|
||||
@@ -180,8 +193,8 @@ void MICROVIEW::setColumnAddress(uint8_t add) {
|
||||
Clear GDRAM inside the LCD controller - mode = ALL
|
||||
Clear screen page buffer - mode = PAGE
|
||||
*/
|
||||
void MICROVIEW::clear(uint8_t mode) {
|
||||
uint8_t page=6, col=0x40;
|
||||
void MicroView::clear(uint8_t mode) {
|
||||
// uint8_t page=6, col=0x40;
|
||||
if (mode==ALL) {
|
||||
for (int i=0;i<8; i++) {
|
||||
setPageAddress(i);
|
||||
@@ -202,8 +215,8 @@ void MICROVIEW::clear(uint8_t mode) {
|
||||
Clear GDRAM inside the LCD controller - mode = ALL with c character.
|
||||
Clear screen page buffer - mode = PAGE with c character.
|
||||
*/
|
||||
void MICROVIEW::clear(uint8_t mode, uint8_t c) {
|
||||
uint8_t page=6, col=0x40;
|
||||
void MicroView::clear(uint8_t mode, uint8_t c) {
|
||||
//uint8_t page=6, col=0x40;
|
||||
if (mode==ALL) {
|
||||
for (int i=0;i<8; i++) {
|
||||
setPageAddress(i);
|
||||
@@ -221,7 +234,7 @@ void MICROVIEW::clear(uint8_t mode, uint8_t c) {
|
||||
}
|
||||
|
||||
// This routine is to transfer the page buffer to the LCD controller's memory.
|
||||
void MICROVIEW::display(void) {
|
||||
void MicroView::display(void) {
|
||||
uint8_t i, j;
|
||||
|
||||
for (i=0; i<6; i++) {
|
||||
@@ -234,9 +247,9 @@ void MICROVIEW::display(void) {
|
||||
}
|
||||
|
||||
#if ARDUINO >= 100
|
||||
size_t MICROVIEW::write(uint8_t c) {
|
||||
size_t MicroView::write(uint8_t c) {
|
||||
#else
|
||||
void MICROVIEW::write(uint8_t c) {
|
||||
void MicroView::write(uint8_t c) {
|
||||
#endif
|
||||
if (c == '\n') {
|
||||
cursorY += fontHeight;
|
||||
@@ -256,16 +269,16 @@ size_t MICROVIEW::write(uint8_t c) {
|
||||
#endif
|
||||
}
|
||||
|
||||
void MICROVIEW::setCursor(uint8_t x, uint8_t y) {
|
||||
void MicroView::setCursor(uint8_t x, uint8_t y) {
|
||||
cursorX=x;
|
||||
cursorY=y;
|
||||
}
|
||||
|
||||
void MICROVIEW::pixel(uint8_t x, uint8_t y) {
|
||||
void MicroView::pixel(uint8_t x, uint8_t y) {
|
||||
pixel(x,y,foreColor,drawMode);
|
||||
}
|
||||
|
||||
void MICROVIEW::pixel(uint8_t x, uint8_t y, uint8_t color, uint8_t mode) {
|
||||
void MicroView::pixel(uint8_t x, uint8_t y, uint8_t color, uint8_t mode) {
|
||||
if ((x<0) || (x>=LCDWIDTH) || (y<0) || (y>=LCDHEIGHT))
|
||||
return;
|
||||
|
||||
@@ -284,13 +297,13 @@ size_t MICROVIEW::write(uint8_t c) {
|
||||
}
|
||||
|
||||
// Draw line using current fore color and current draw mode
|
||||
void MICROVIEW::line(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1) {
|
||||
void MicroView::line(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1) {
|
||||
line(x0,y0,x1,y1,foreColor,drawMode);
|
||||
}
|
||||
|
||||
// Draw line using color and mode
|
||||
// bresenham's algorithm
|
||||
void MICROVIEW::line(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, uint8_t color, uint8_t mode) {
|
||||
void MicroView::line(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, uint8_t color, uint8_t mode) {
|
||||
uint8_t steep = abs(y1 - y0) > abs(x1 - x0);
|
||||
if (steep) {
|
||||
swap(x0, y0);
|
||||
@@ -329,32 +342,32 @@ size_t MICROVIEW::write(uint8_t c) {
|
||||
}
|
||||
|
||||
// Draw horizontal line using current fore color and current draw mode
|
||||
void MICROVIEW::lineH(uint8_t x, uint8_t y, uint8_t width) {
|
||||
void MicroView::lineH(uint8_t x, uint8_t y, uint8_t width) {
|
||||
line(x,y,x+width,y,foreColor,drawMode);
|
||||
}
|
||||
|
||||
// Draw horizontal line using color and draw mode
|
||||
void MICROVIEW::lineH(uint8_t x, uint8_t y, uint8_t width, uint8_t color, uint8_t mode) {
|
||||
void MicroView::lineH(uint8_t x, uint8_t y, uint8_t width, uint8_t color, uint8_t mode) {
|
||||
line(x,y,x+width,y,color,mode);
|
||||
}
|
||||
|
||||
// Draw vertical line using current fore color and current draw mode
|
||||
void MICROVIEW::lineV(uint8_t x, uint8_t y, uint8_t height) {
|
||||
void MicroView::lineV(uint8_t x, uint8_t y, uint8_t height) {
|
||||
line(x,y,x,y+height,foreColor,drawMode);
|
||||
}
|
||||
|
||||
// Draw vertical line using color and draw mode
|
||||
void MICROVIEW::lineV(uint8_t x, uint8_t y, uint8_t height, uint8_t color, uint8_t mode) {
|
||||
void MicroView::lineV(uint8_t x, uint8_t y, uint8_t height, uint8_t color, uint8_t mode) {
|
||||
line(x,y,x,y+height,color,mode);
|
||||
}
|
||||
|
||||
// Draw rectangle using current fore color and current draw mode
|
||||
void MICROVIEW::rect(uint8_t x, uint8_t y, uint8_t width, uint8_t height) {
|
||||
void MicroView::rect(uint8_t x, uint8_t y, uint8_t width, uint8_t height) {
|
||||
rect(x,y,width,height,foreColor,drawMode);
|
||||
}
|
||||
|
||||
// Draw rectangle using color and draw mode
|
||||
void MICROVIEW::rect(uint8_t x, uint8_t y, uint8_t width, uint8_t height, uint8_t color , uint8_t mode) {
|
||||
void MicroView::rect(uint8_t x, uint8_t y, uint8_t width, uint8_t height, uint8_t color , uint8_t mode) {
|
||||
uint8_t tempHeight;
|
||||
|
||||
lineH(x,y, width, color, mode);
|
||||
@@ -372,12 +385,12 @@ size_t MICROVIEW::write(uint8_t c) {
|
||||
|
||||
|
||||
// Draw filled rectangle using current fore color and current draw mode
|
||||
void MICROVIEW::rectFill(uint8_t x, uint8_t y, uint8_t width, uint8_t height) {
|
||||
void MicroView::rectFill(uint8_t x, uint8_t y, uint8_t width, uint8_t height) {
|
||||
rectFill(x,y,width,height,foreColor,drawMode);
|
||||
}
|
||||
|
||||
// Draw filled rectangle using color and mode
|
||||
void MICROVIEW::rectFill(uint8_t x, uint8_t y, uint8_t width, uint8_t height, uint8_t color , uint8_t mode) {
|
||||
void MicroView::rectFill(uint8_t x, uint8_t y, uint8_t width, uint8_t height, uint8_t color , uint8_t mode) {
|
||||
// TODO - need to optimise the memory map draw so that this function will not call pixel one by one
|
||||
for (int i=x; i<x+width;i++) {
|
||||
lineV(i,y, height, color, mode);
|
||||
@@ -385,12 +398,12 @@ size_t MICROVIEW::write(uint8_t c) {
|
||||
}
|
||||
|
||||
// Draw circle using current fore color and current draw mode
|
||||
void MICROVIEW::circle(uint8_t x0, uint8_t y0, uint8_t radius) {
|
||||
void MicroView::circle(uint8_t x0, uint8_t y0, uint8_t radius) {
|
||||
circle(x0,y0,radius,foreColor,drawMode);
|
||||
}
|
||||
|
||||
// Draw circle using color and mode
|
||||
void MICROVIEW::circle(uint8_t x0, uint8_t y0, uint8_t radius, uint8_t color, uint8_t mode) {
|
||||
void MicroView::circle(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;
|
||||
@@ -428,12 +441,12 @@ size_t MICROVIEW::write(uint8_t c) {
|
||||
|
||||
|
||||
// Draw filled circle using current fore color and current draw mode
|
||||
void MICROVIEW::circleFill(uint8_t x0, uint8_t y0, uint8_t radius) {
|
||||
void MicroView::circleFill(uint8_t x0, uint8_t y0, uint8_t radius) {
|
||||
circleFill(x0,y0,radius,foreColor,drawMode);
|
||||
}
|
||||
|
||||
// Draw filled circle using color and mode
|
||||
void MICROVIEW::circleFill(uint8_t x0, uint8_t y0, uint8_t radius, uint8_t color, uint8_t mode) {
|
||||
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;
|
||||
@@ -469,41 +482,41 @@ size_t MICROVIEW::write(uint8_t c) {
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t MICROVIEW::getLCDHeight(void) {
|
||||
uint8_t MicroView::getLCDHeight(void) {
|
||||
return LCDHEIGHT;
|
||||
}
|
||||
|
||||
uint8_t MICROVIEW::getLCDWidth(void) {
|
||||
uint8_t MicroView::getLCDWidth(void) {
|
||||
return LCDWIDTH;
|
||||
}
|
||||
|
||||
uint8_t MICROVIEW::getFontWidth(void) {
|
||||
uint8_t MicroView::getFontWidth(void) {
|
||||
return fontWidth;
|
||||
}
|
||||
|
||||
uint8_t MICROVIEW::getFontHeight(void) {
|
||||
uint8_t MicroView::getFontHeight(void) {
|
||||
return fontHeight;
|
||||
}
|
||||
|
||||
uint8_t MICROVIEW::getFontStartChar(void) {
|
||||
uint8_t MicroView::getFontStartChar(void) {
|
||||
return fontStartChar;
|
||||
}
|
||||
|
||||
uint8_t MICROVIEW::getFontTotalChar(void) {
|
||||
uint8_t MicroView::getFontTotalChar(void) {
|
||||
return fontTotalChar;
|
||||
}
|
||||
|
||||
uint8_t MICROVIEW::getTotalFonts(void) {
|
||||
uint8_t MicroView::getTotalFonts(void) {
|
||||
return TOTALFONTS;
|
||||
}
|
||||
|
||||
uint8_t MICROVIEW::getFontType(void) {
|
||||
uint8_t MicroView::getFontType(void) {
|
||||
return fontType;
|
||||
}
|
||||
|
||||
uint8_t MICROVIEW::setFontType(uint8_t type) {
|
||||
uint8_t MicroView::setFontType(uint8_t type) {
|
||||
if ((type>=TOTALFONTS) || (type<0))
|
||||
return -1;
|
||||
return false;
|
||||
|
||||
fontType=type;
|
||||
fontWidth=pgm_read_byte(fontsPointer[fontType]+0);
|
||||
@@ -511,24 +524,24 @@ size_t MICROVIEW::write(uint8_t c) {
|
||||
fontStartChar=pgm_read_byte(fontsPointer[fontType]+2);
|
||||
fontTotalChar=pgm_read_byte(fontsPointer[fontType]+3);
|
||||
fontMapWidth=(pgm_read_byte(fontsPointer[fontType]+4)*100)+pgm_read_byte(fontsPointer[fontType]+5); // two bytes values into integer 16
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void MICROVIEW::setColor(uint8_t color) {
|
||||
void MicroView::setColor(uint8_t color) {
|
||||
foreColor=color;
|
||||
}
|
||||
|
||||
void MICROVIEW::setDrawMode(uint8_t mode) {
|
||||
void MicroView::setDrawMode(uint8_t mode) {
|
||||
drawMode=mode;
|
||||
}
|
||||
|
||||
// Draw character using current fore color and current draw mode
|
||||
void MICROVIEW::drawChar(uint8_t x, uint8_t y, uint8_t c) {
|
||||
void MicroView::drawChar(uint8_t x, uint8_t y, uint8_t c) {
|
||||
drawChar(x,y,c,foreColor,drawMode);
|
||||
}
|
||||
|
||||
// Draw character using color and mode
|
||||
void MICROVIEW::drawChar(uint8_t x, uint8_t y, uint8_t c, uint8_t color, uint8_t mode) {
|
||||
void MicroView::drawChar(uint8_t x, uint8_t y, uint8_t c, uint8_t color, uint8_t mode) {
|
||||
// TODO - New routine to take font of any height, at the moment limited to font height in multiple of 8 pixels
|
||||
|
||||
uint8_t rowsToDraw,row, tempC;
|
||||
@@ -620,11 +633,11 @@ size_t MICROVIEW::write(uint8_t c) {
|
||||
|
||||
}
|
||||
|
||||
void MICROVIEW::stopScroll(void){
|
||||
void MicroView::stopScroll(void){
|
||||
command(DEACTIVATESCROLL);
|
||||
}
|
||||
|
||||
void MICROVIEW::scrollRight(uint8_t start, uint8_t stop){
|
||||
void MicroView::scrollRight(uint8_t start, uint8_t stop){
|
||||
if (stop<start) // stop must be larger or equal to start
|
||||
return;
|
||||
stopScroll(); // need to disable scrolling before starting to avoid memory corrupt
|
||||
@@ -638,6 +651,148 @@ size_t MICROVIEW::write(uint8_t c) {
|
||||
command(ACTIVATESCROLL);
|
||||
}
|
||||
|
||||
MICROVIEW uView;
|
||||
MicroViewWidget::MicroViewWidget(uint8_t newx, uint8_t newy, int16_t min, int16_t max) {
|
||||
setX(newx);
|
||||
setY(newy);
|
||||
value=0;
|
||||
if (min>max) {
|
||||
setMinValue(max);
|
||||
setMaxValue(min);
|
||||
}
|
||||
else {
|
||||
setMinValue(min);
|
||||
setMaxValue(max);
|
||||
}
|
||||
setValue(min);
|
||||
}
|
||||
|
||||
uint8_t MicroViewWidget::getX() { return x; }
|
||||
uint8_t MicroViewWidget::getY() { return y; }
|
||||
void MicroViewWidget::setX(uint8_t newx) { x = newx; }
|
||||
void MicroViewWidget::setY(uint8_t newy) { y = newy; }
|
||||
|
||||
int16_t MicroViewWidget::getMinValue() { return minValue; }
|
||||
int16_t MicroViewWidget::getMaxValue() { return maxValue; }
|
||||
|
||||
int16_t MicroViewWidget::getValue() { return value; }
|
||||
|
||||
void MicroViewWidget::setMinValue(int16_t min) { minValue=min; }
|
||||
void MicroViewWidget::setMaxValue(int16_t max) { maxValue=max; }
|
||||
void MicroViewWidget::setValue(int16_t val) {
|
||||
if (val<=maxValue) {
|
||||
value=val;
|
||||
this->draw();
|
||||
}
|
||||
}
|
||||
|
||||
MicroViewSlider::MicroViewSlider(uint8_t newx, uint8_t newy, int16_t min, int16_t max):MicroViewWidget(newx, newy, min, max) {
|
||||
totalTicks=40;
|
||||
needFirstDraw=true;
|
||||
prevValue=getMinValue();
|
||||
}
|
||||
|
||||
void MicroViewSlider::draw() {
|
||||
uint8_t offsetX, offsetY;
|
||||
uint8_t tickPosition=0;
|
||||
char strBuffer[5];
|
||||
|
||||
offsetX=getX();
|
||||
offsetY=getY();
|
||||
|
||||
// Draw major tickers
|
||||
for (uint8_t i=0; i<5;i++) {
|
||||
uView.lineV(offsetX+1+(i*10), offsetY+3, 5);
|
||||
}
|
||||
// Draw minor tickers
|
||||
for (uint8_t i=0; i<4;i++) {
|
||||
uView.lineV(offsetX+3+(i*2), offsetY+5, 3);
|
||||
}
|
||||
for (uint8_t i=0; i<4;i++) {
|
||||
uView.lineV(offsetX+13+(i*2), offsetY+5, 3);
|
||||
}
|
||||
for (uint8_t i=0; i<4;i++) {
|
||||
uView.lineV(offsetX+23+(i*2), offsetY+5, 3);
|
||||
}
|
||||
for (uint8_t i=0; i<4;i++) {
|
||||
uView.lineV(offsetX+33+(i*2), offsetY+5, 3);
|
||||
}
|
||||
|
||||
if (needFirstDraw) {
|
||||
uView.lineH(offsetX,offsetY, 3, WHITE,XOR);
|
||||
uView.pixel(offsetX+1,offsetY+1, WHITE,XOR);
|
||||
needFirstDraw=false;
|
||||
}
|
||||
else {
|
||||
// Draw previous pointer in XOR mode to erase it
|
||||
tickPosition= (((float)prevValue/(float)(getMaxValue()-getMinValue()))*totalTicks);
|
||||
uView.lineH(offsetX+tickPosition,offsetY, 3, WHITE, XOR);
|
||||
uView.pixel(offsetX+1+tickPosition,offsetY+1, WHITE, XOR);
|
||||
// Draw current pointer
|
||||
tickPosition= (((float)getValue()/(float)(getMaxValue()-getMinValue()))*totalTicks);
|
||||
uView.lineH(offsetX+tickPosition,offsetY, 3, WHITE, XOR);
|
||||
uView.pixel(offsetX+1+tickPosition,offsetY+1, WHITE, XOR);
|
||||
|
||||
}
|
||||
|
||||
// Draw value
|
||||
uView.setCursor(offsetX+44,offsetY);
|
||||
sprintf(strBuffer,"%3d", getValue()); // we need to force only 3 digit or it will go over the display.
|
||||
uView.print(strBuffer);
|
||||
prevValue=getValue();
|
||||
}
|
||||
|
||||
void SPIClass::begin() {
|
||||
|
||||
// Set SS to high so a connected chip will be "deselected" by default
|
||||
digitalWrite(SS, HIGH);
|
||||
|
||||
// When the SS pin is set as OUTPUT, it can be used as
|
||||
// a general purpose output port (it doesn't influence
|
||||
// SPI operations).
|
||||
pinMode(SS, OUTPUT);
|
||||
|
||||
// Warning: if the SS pin ever becomes a LOW INPUT then SPI
|
||||
// automatically switches to Slave, so the data direction of
|
||||
// the SS pin MUST be kept as OUTPUT.
|
||||
SPCR |= _BV(MSTR);
|
||||
SPCR |= _BV(SPE);
|
||||
|
||||
// Set direction register for SCK and MOSI pin.
|
||||
// MISO pin automatically overrides to INPUT.
|
||||
// By doing this AFTER enabling SPI, we avoid accidentally
|
||||
// clocking in a single bit since the lines go directly
|
||||
// from "input" to SPI control.
|
||||
// http://code.google.com/p/arduino/issues/detail?id=888
|
||||
pinMode(SCK, OUTPUT);
|
||||
pinMode(MOSI, OUTPUT);
|
||||
}
|
||||
|
||||
|
||||
void SPIClass::end() {
|
||||
SPCR &= ~_BV(SPE);
|
||||
}
|
||||
|
||||
void SPIClass::setBitOrder(uint8_t bitOrder)
|
||||
{
|
||||
if(bitOrder == LSBFIRST) {
|
||||
SPCR |= _BV(DORD);
|
||||
} else {
|
||||
SPCR &= ~(_BV(DORD));
|
||||
}
|
||||
}
|
||||
|
||||
void SPIClass::setDataMode(uint8_t mode)
|
||||
{
|
||||
SPCR = (SPCR & ~SPI_MODE_MASK) | mode;
|
||||
}
|
||||
|
||||
void SPIClass::setClockDivider(uint8_t rate)
|
||||
{
|
||||
SPCR = (SPCR & ~SPI_CLOCK_MASK) | (rate & SPI_CLOCK_MASK);
|
||||
SPSR = (SPSR & ~SPI_2XCLOCK_MASK) | ((rate >> 2) & SPI_2XCLOCK_MASK);
|
||||
}
|
||||
|
||||
SPIClass MVSPI;
|
||||
MicroView uView;
|
||||
|
||||
|
||||
|
||||
112
MicroView.h
112
MicroView.h
@@ -1,20 +1,17 @@
|
||||
#ifndef MICROVIEW_H
|
||||
#define MICROVIEW_H
|
||||
|
||||
#if ARDUINO >= 100
|
||||
#include "Arduino.h"
|
||||
#include "Print.h"
|
||||
#else
|
||||
#include "WProgram.h"
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#include <Arduino.h>
|
||||
#include <avr/pgmspace.h>
|
||||
|
||||
#define swap(a, b) { uint8_t t = a; a = b; b = t; }
|
||||
|
||||
#define DC 8
|
||||
#define SCK 13
|
||||
#define MOSI 11
|
||||
//#define SCK 13
|
||||
//#define MOSI 11
|
||||
#define RESET 12
|
||||
#define CS 10
|
||||
//#define CS 10
|
||||
|
||||
#define BLACK 0
|
||||
#define WHITE 1
|
||||
@@ -62,9 +59,9 @@
|
||||
#define VERTICALRIGHTHORIZONTALSCROLL 0x29
|
||||
#define VERTICALLEFTHORIZONTALSCROLL 0x2A
|
||||
|
||||
class MICROVIEW : public Print{
|
||||
class MicroView : public Print{
|
||||
public:
|
||||
MICROVIEW(void) {};
|
||||
MicroView(void) {};
|
||||
void begin(void);
|
||||
|
||||
#if ARDUINO >= 100
|
||||
@@ -127,13 +124,100 @@ public:
|
||||
|
||||
private:
|
||||
//uint8_t cs;
|
||||
volatile uint8_t *mosiport, *sckport, *csport, *dcport; // use volatile because these are fixed location port address
|
||||
uint8_t mosipinmask, sckpinmask, cspinmask, dcpinmask;
|
||||
volatile uint8_t *mosiport, *sckport, *ssport, *dcport; // use volatile because these are fixed location port address
|
||||
uint8_t mosipinmask, sckpinmask, sspinmask, dcpinmask;
|
||||
uint8_t foreColor,drawMode,fontWidth, fontHeight, fontType, fontStartChar, fontTotalChar, cursorX, cursorY;
|
||||
uint16_t fontMapWidth;
|
||||
//unsigned char *fontsPointer[TOTALFONTS];
|
||||
static const unsigned char *fontsPointer[];
|
||||
};
|
||||
|
||||
extern MICROVIEW uView;
|
||||
class MicroViewWidget {
|
||||
public:
|
||||
MicroViewWidget(uint8_t newx, uint8_t newy, int16_t min, int16_t max);
|
||||
uint8_t getX();
|
||||
uint8_t getY();
|
||||
void setX(uint8_t newx);
|
||||
void setY(uint8_t newy);
|
||||
|
||||
int16_t getMinValue();
|
||||
int16_t getMaxValue();
|
||||
int16_t getValue();
|
||||
void setMaxValue(int16_t max);
|
||||
void setMinValue(int16_t max);
|
||||
void setValue(int16_t val);
|
||||
virtual void draw(){};
|
||||
private:
|
||||
uint8_t x;
|
||||
uint8_t y;
|
||||
int16_t maxValue;
|
||||
int16_t minValue;
|
||||
int16_t value;
|
||||
};
|
||||
|
||||
class MicroViewSlider: public MicroViewWidget{
|
||||
public:
|
||||
MicroViewSlider(uint8_t newx, uint8_t newy, int16_t min, int16_t max);
|
||||
void draw();
|
||||
private:
|
||||
uint8_t totalTicks;
|
||||
bool needFirstDraw;
|
||||
int16_t prevValue;
|
||||
};
|
||||
|
||||
|
||||
#define SPI_CLOCK_DIV4 0x00
|
||||
#define SPI_CLOCK_DIV16 0x01
|
||||
#define SPI_CLOCK_DIV64 0x02
|
||||
#define SPI_CLOCK_DIV128 0x03
|
||||
#define SPI_CLOCK_DIV2 0x04
|
||||
#define SPI_CLOCK_DIV8 0x05
|
||||
#define SPI_CLOCK_DIV32 0x06
|
||||
//#define SPI_CLOCK_DIV64 0x07
|
||||
|
||||
#define SPI_MODE0 0x00
|
||||
#define SPI_MODE1 0x04
|
||||
#define SPI_MODE2 0x08
|
||||
#define SPI_MODE3 0x0C
|
||||
|
||||
#define SPI_MODE_MASK 0x0C // CPOL = bit 3, CPHA = bit 2 on SPCR
|
||||
#define SPI_CLOCK_MASK 0x03 // SPR1 = bit 1, SPR0 = bit 0 on SPCR
|
||||
#define SPI_2XCLOCK_MASK 0x01 // SPI2X = bit 0 on SPSR
|
||||
|
||||
class SPIClass {
|
||||
public:
|
||||
inline static byte transfer(byte _data);
|
||||
|
||||
// SPI Configuration methods
|
||||
|
||||
inline static void attachInterrupt();
|
||||
inline static void detachInterrupt(); // Default
|
||||
|
||||
static void begin(); // Default
|
||||
static void end();
|
||||
|
||||
static void setBitOrder(uint8_t);
|
||||
static void setDataMode(uint8_t);
|
||||
static void setClockDivider(uint8_t);
|
||||
};
|
||||
|
||||
extern SPIClass MVSPI;
|
||||
|
||||
byte SPIClass::transfer(byte _data) {
|
||||
SPDR = _data;
|
||||
while (!(SPSR & _BV(SPIF)))
|
||||
;
|
||||
return SPDR;
|
||||
}
|
||||
|
||||
void SPIClass::attachInterrupt() {
|
||||
SPCR |= _BV(SPIE);
|
||||
}
|
||||
|
||||
void SPIClass::detachInterrupt() {
|
||||
SPCR &= ~_BV(SPIE);
|
||||
}
|
||||
|
||||
|
||||
extern MicroView uView;
|
||||
#endif
|
||||
15
README.md
15
README.md
@@ -8,20 +8,17 @@ Arduino library for MicroView.
|
||||
|
||||
## Required Libraries
|
||||
|
||||
1. SPI.h
|
||||
2. [Time.h](http://www.pjrc.com/teensy/td_libs_Time.html) NOTE: Only required when using clock/time functions.
|
||||
1. [Time.h](http://www.pjrc.com/teensy/td_libs_Time.html) NOTE: Only required when using clock/time functions. For example the MicroViewDemo in the example folder.
|
||||
|
||||
## Installation Instructions
|
||||
## Installation
|
||||
|
||||
1. Extract / Check out to Arduino's libraries folder.
|
||||
2. Start Arduino IDE.
|
||||
3. MicroView example is located at, File--->Example--->MicroView--->MicroViewDemo
|
||||
|
||||
### Example
|
||||
|
||||
<pre><code>
|
||||
#include <MicroView.h>
|
||||
#include <SPI.h>
|
||||
|
||||
void setup() {
|
||||
uView.begin();
|
||||
@@ -40,6 +37,14 @@ void loop() {
|
||||
</code></pre>
|
||||
|
||||
## History
|
||||
**v1.05b: 6th February by JP Liew**
|
||||
* changed MICROVIEW class name to MicroView
|
||||
* created MICROVIEWWIDGET class
|
||||
* added routines to draw widget
|
||||
* added slider widget
|
||||
* merged MicroViewWidget into MicroView
|
||||
* merged SPI.h into MicroView
|
||||
|
||||
|
||||
**v1.04b: 3rd February 2014 by JP Liew**
|
||||
* declared permanent uView variable.
|
||||
|
||||
@@ -1,48 +1,45 @@
|
||||
#include <MicroView.h>
|
||||
#include <SPI.h>
|
||||
#include <Time.h>
|
||||
|
||||
#define PI 3.141592654
|
||||
//#define PI 3.141592654
|
||||
#define clocksize 24
|
||||
|
||||
MICROVIEW mv;
|
||||
|
||||
uint8_t onDelay=5; // This is the erase delay in milliseconds, if there is no delay, the draw/erase will be too fast to be seen.
|
||||
uint8_t onDelay=5; // This is the on delay in milliseconds, if there is no on delay, the erase will be too fast to clean up the screen.
|
||||
|
||||
void setup() {
|
||||
mv.begin(); // Begin of MicroView
|
||||
mv.clear(ALL); // Erase hardware memory inside the OLED controller
|
||||
mv.display(); // Display the content in the buffer memory, by default it is the MicroView logo
|
||||
uView.begin(); // Begin of MicroView
|
||||
uView.clear(ALL); // Erase hardware memory inside the OLED controller
|
||||
uView.display(); // Display the content in the buffer memory, by default it is the MicroView logo
|
||||
setTime(10,10,01,17,1,2014);
|
||||
delay(500);
|
||||
mv.clear(PAGE); // Erase the memory buffer, when next mv.display() is called, the OLED will be cleared.
|
||||
uView.clear(PAGE); // Erase the memory buffer, when next uView.display() is called, the OLED will be cleared.
|
||||
}
|
||||
|
||||
void loop() {
|
||||
int i;
|
||||
static long counter=99999;
|
||||
static long mSec=millis()+1000;
|
||||
static double counter=99999;
|
||||
static unsigned long mSec=millis()+1000;
|
||||
static uint8_t x0,y0,x1,y1;
|
||||
static float degresshour,degressmin,degresssec,hourx,houry,minx,miny,secx,secy;
|
||||
static boolean drawnFirst=false;
|
||||
|
||||
mv.setFontType(0); // set font type 0, please see declaration in MicroView.cpp
|
||||
mv.setCursor(27,0); // points cursor to x=27 y=0
|
||||
mv.print(12);
|
||||
mv.setCursor(30,mv.getLCDHeight()-mv.getFontHeight());
|
||||
mv.print(6);
|
||||
mv.setCursor(0,mv.getLCDHeight() /2-(mv.getFontHeight()/2));
|
||||
mv.print(9);
|
||||
mv.setCursor(mv.getLCDWidth()-mv.getFontWidth(),mv.getLCDWidth()/2-(mv.getFontHeight()/2));
|
||||
mv.print(3);
|
||||
mv.display(); // display the memory buffer drawn
|
||||
uView.setFontType(0); // set font type 0, please see declaration in MicroView.cpp
|
||||
uView.setCursor(27,0); // points cursor to x=27 y=0
|
||||
uView.print(12);
|
||||
uView.setCursor(30,uView.getLCDHeight()-uView.getFontHeight());
|
||||
uView.print(6);
|
||||
uView.setCursor(0,uView.getLCDHeight() /2-(uView.getFontHeight()/2));
|
||||
uView.print(9);
|
||||
uView.setCursor(uView.getLCDWidth()-uView.getFontWidth(),uView.getLCDWidth()/2-(uView.getFontHeight()/2));
|
||||
uView.print(3);
|
||||
uView.display(); // display the memory buffer drawn
|
||||
|
||||
while ((second() % 10 )!=0) {
|
||||
if (mSec!=second()) {
|
||||
while ((second() % 11 )!=0) {
|
||||
if (mSec!=(unsigned long)second()) {
|
||||
if (drawnFirst) {
|
||||
mv.line(32,24,32+hourx,24+houry,WHITE,XOR);
|
||||
mv.line(32,24,32+minx,24+miny,WHITE,XOR);
|
||||
mv.line(32,24,32+secx,24+secy,WHITE,XOR);
|
||||
uView.line(32,24,32+hourx,24+houry,WHITE,XOR);
|
||||
uView.line(32,24,32+minx,24+miny,WHITE,XOR);
|
||||
uView.line(32,24,32+secx,24+secy,WHITE,XOR);
|
||||
}
|
||||
|
||||
degresshour = (((hour() * 360) / 12) + 270) * (PI / 180);
|
||||
@@ -59,103 +56,103 @@ void loop() {
|
||||
secy = sin(degresssec) * (clocksize / 1.1);
|
||||
|
||||
|
||||
mv.line(32,24,32+hourx,24+houry,WHITE,XOR);
|
||||
mv.line(32,24,32+minx,24+miny,WHITE,XOR);
|
||||
mv.line(32,24,32+secx,24+secy,WHITE,XOR);
|
||||
uView.line(32,24,32+hourx,24+houry,WHITE,XOR);
|
||||
uView.line(32,24,32+minx,24+miny,WHITE,XOR);
|
||||
uView.line(32,24,32+secx,24+secy,WHITE,XOR);
|
||||
drawnFirst=true;
|
||||
mv.display();
|
||||
uView.display();
|
||||
|
||||
mSec=second();
|
||||
}
|
||||
}
|
||||
drawnFirst=false;
|
||||
mv.clear(PAGE);
|
||||
uView.clear(PAGE);
|
||||
|
||||
int maxX=40;
|
||||
onDelay=30;
|
||||
mv.setFontType(0);
|
||||
mv.setCursor(0,40);
|
||||
mv.print(" SPRITE ");
|
||||
uView.setFontType(0);
|
||||
uView.setCursor(0,40);
|
||||
uView.print(" SPRITE ");
|
||||
for (int x=0; x<maxX;x+=2) {
|
||||
mv.setFontType(3);
|
||||
mv.drawChar(x,0,48,WHITE, XOR);
|
||||
mv.setFontType(4);
|
||||
mv.drawChar(maxX-x,10,48,WHITE,XOR);
|
||||
uView.setFontType(4);
|
||||
uView.drawChar(x,0,48,WHITE, XOR);
|
||||
uView.setFontType(5);
|
||||
uView.drawChar(maxX-x,10,48,WHITE,XOR);
|
||||
|
||||
mv.setFontType(5);
|
||||
mv.drawChar(x,32,48,WHITE,XOR);
|
||||
uView.setFontType(6);
|
||||
uView.drawChar(x,32,48,WHITE,XOR);
|
||||
|
||||
mv.display();
|
||||
uView.display();
|
||||
delay(onDelay);
|
||||
mv.setFontType(3);
|
||||
mv.drawChar(x,0,48,WHITE, XOR);
|
||||
mv.setFontType(4);
|
||||
mv.drawChar(maxX-x,10,48,WHITE,XOR);
|
||||
mv.setFontType(5);
|
||||
mv.drawChar(x,32,48,WHITE,XOR);
|
||||
uView.setFontType(4);
|
||||
uView.drawChar(x,0,48,WHITE, XOR);
|
||||
uView.setFontType(5);
|
||||
uView.drawChar(maxX-x,10,48,WHITE,XOR);
|
||||
uView.setFontType(6);
|
||||
uView.drawChar(x,32,48,WHITE,XOR);
|
||||
|
||||
mv.display();
|
||||
mv.setFontType(3);
|
||||
mv.drawChar(x,0,49,WHITE, XOR);
|
||||
mv.setFontType(4);
|
||||
mv.drawChar(maxX-x,10,49,WHITE,XOR);
|
||||
mv.setFontType(5);
|
||||
mv.drawChar(x,32,49,WHITE,XOR);
|
||||
uView.display();
|
||||
uView.setFontType(4);
|
||||
uView.drawChar(x,0,49,WHITE, XOR);
|
||||
uView.setFontType(5);
|
||||
uView.drawChar(maxX-x,10,49,WHITE,XOR);
|
||||
uView.setFontType(6);
|
||||
uView.drawChar(x,32,49,WHITE,XOR);
|
||||
|
||||
mv.display();
|
||||
uView.display();
|
||||
delay(onDelay);
|
||||
mv.setFontType(3);
|
||||
mv.drawChar(x,0,49,WHITE, XOR);
|
||||
mv.setFontType(4);
|
||||
mv.drawChar(maxX-x,10,49,WHITE,XOR);
|
||||
mv.setFontType(5);
|
||||
mv.drawChar(x,32,49,WHITE,XOR);
|
||||
mv.display();
|
||||
uView.setFontType(4);
|
||||
uView.drawChar(x,0,49,WHITE, XOR);
|
||||
uView.setFontType(5);
|
||||
uView.drawChar(maxX-x,10,49,WHITE,XOR);
|
||||
uView.setFontType(6);
|
||||
uView.drawChar(x,32,49,WHITE,XOR);
|
||||
uView.display();
|
||||
}
|
||||
|
||||
for (int x=maxX; x>0;x-=2) {
|
||||
mv.setFontType(3);
|
||||
mv.drawChar(x,10,48,WHITE, XOR);
|
||||
mv.setFontType(4);
|
||||
mv.drawChar(40-x,0,48,WHITE,XOR);
|
||||
mv.setFontType(5);
|
||||
mv.drawChar(x,32,48,WHITE,XOR);
|
||||
uView.setFontType(4);
|
||||
uView.drawChar(x,10,48,WHITE, XOR);
|
||||
uView.setFontType(5);
|
||||
uView.drawChar(40-x,0,48,WHITE,XOR);
|
||||
uView.setFontType(6);
|
||||
uView.drawChar(x,32,48,WHITE,XOR);
|
||||
|
||||
mv.display();
|
||||
uView.display();
|
||||
delay(onDelay);
|
||||
mv.setFontType(3);
|
||||
mv.drawChar(x,10,48,WHITE, XOR);
|
||||
mv.setFontType(4);
|
||||
mv.drawChar(40-x,0,48,WHITE,XOR);
|
||||
mv.setFontType(5);
|
||||
mv.drawChar(x,32,48,WHITE,XOR);
|
||||
uView.setFontType(4);
|
||||
uView.drawChar(x,10,48,WHITE, XOR);
|
||||
uView.setFontType(5);
|
||||
uView.drawChar(40-x,0,48,WHITE,XOR);
|
||||
uView.setFontType(6);
|
||||
uView.drawChar(x,32,48,WHITE,XOR);
|
||||
|
||||
mv.display();
|
||||
mv.setFontType(3);
|
||||
mv.drawChar(x,10,49,WHITE, XOR);
|
||||
mv.setFontType(4);
|
||||
mv.drawChar(40-x,0,49,WHITE,XOR);
|
||||
mv.setFontType(5);
|
||||
mv.drawChar(x,32,49,WHITE,XOR);
|
||||
uView.display();
|
||||
uView.setFontType(4);
|
||||
uView.drawChar(x,10,49,WHITE, XOR);
|
||||
uView.setFontType(5);
|
||||
uView.drawChar(40-x,0,49,WHITE,XOR);
|
||||
uView.setFontType(6);
|
||||
uView.drawChar(x,32,49,WHITE,XOR);
|
||||
|
||||
mv.display();
|
||||
uView.display();
|
||||
delay(onDelay);
|
||||
mv.setFontType(3);
|
||||
mv.drawChar(x,10,49,WHITE, XOR);
|
||||
mv.setFontType(4);
|
||||
mv.drawChar(40-x,0,49,WHITE,XOR);
|
||||
mv.setFontType(5);
|
||||
mv.drawChar(x,32,49,WHITE,XOR);
|
||||
uView.setFontType(4);
|
||||
uView.drawChar(x,10,49,WHITE, XOR);
|
||||
uView.setFontType(5);
|
||||
uView.drawChar(40-x,0,49,WHITE,XOR);
|
||||
uView.setFontType(6);
|
||||
uView.drawChar(x,32,49,WHITE,XOR);
|
||||
|
||||
mv.display();
|
||||
uView.display();
|
||||
}
|
||||
|
||||
|
||||
onDelay=5;
|
||||
mv.setFontType(0);
|
||||
mv.setCursor(0,40);
|
||||
mv.print(" LINE ");
|
||||
mv.display();
|
||||
uView.setFontType(0);
|
||||
uView.setCursor(0,40);
|
||||
uView.print(" LINE ");
|
||||
uView.display();
|
||||
delay(500);
|
||||
|
||||
for (i=0; i<150;i++) {
|
||||
@@ -164,84 +161,108 @@ void loop() {
|
||||
y0=random(48);
|
||||
y1=random(48);
|
||||
|
||||
mv.line(x0,y0,x1,y1, WHITE, XOR); // draw line from x0,y0 to x1,y1 using WHITE color and XOR draw mode
|
||||
mv.display();
|
||||
uView.line(x0,y0,x1,y1, WHITE, XOR); // draw line from x0,y0 to x1,y1 using WHITE color and XOR draw mode
|
||||
uView.display();
|
||||
delay(onDelay);
|
||||
mv.line(x0,y0,x1,y1, WHITE,XOR);
|
||||
mv.display();
|
||||
uView.line(x0,y0,x1,y1, WHITE,XOR);
|
||||
uView.display();
|
||||
}
|
||||
|
||||
mv.setCursor(0,40);
|
||||
mv.print("RECTANGLE ");
|
||||
mv.display();
|
||||
uView.setCursor(0,40);
|
||||
uView.print("RECTANGLE ");
|
||||
uView.display();
|
||||
delay(500);
|
||||
|
||||
x0=0;y0=0;x1=0;y1=0;
|
||||
for (i=1; i<64;i++) {
|
||||
y1=i;
|
||||
if (y1>47) y1=47;
|
||||
mv.rect(x0,y0,i,y1,WHITE,XOR); // draw rectangle from x0,y0 with width of i and height of y1 using WHITE color and XOR draw mode
|
||||
mv.display();
|
||||
uView.rect(x0,y0,i,y1,WHITE,XOR); // draw rectangle from x0,y0 with width of i and height of y1 using WHITE color and XOR draw mode
|
||||
uView.display();
|
||||
delay(onDelay);
|
||||
mv.rect(x0,y0,i,y1,WHITE,XOR);
|
||||
mv.display();
|
||||
uView.rect(x0,y0,i,y1,WHITE,XOR);
|
||||
uView.display();
|
||||
}
|
||||
|
||||
mv.setCursor(0,40);
|
||||
mv.print(" CIRCLE ");
|
||||
mv.display();
|
||||
uView.setCursor(0,40);
|
||||
uView.print(" CIRCLE ");
|
||||
uView.display();
|
||||
delay(500);
|
||||
|
||||
x0=32;y0=24;
|
||||
for (i=0;i<32;i++) {
|
||||
mv.circle(x0,y0,i,WHITE,XOR); // draw circle at x0,y0 with radius of i using WHITE color and XOR draw mode
|
||||
mv.display();
|
||||
uView.circle(x0,y0,i,WHITE,XOR); // draw circle at x0,y0 with radius of i using WHITE color and XOR draw mode
|
||||
uView.display();
|
||||
delay(onDelay);
|
||||
mv.circle(x0,y0,i,WHITE,XOR);
|
||||
mv.display();
|
||||
uView.circle(x0,y0,i,WHITE,XOR);
|
||||
uView.display();
|
||||
delay(onDelay);
|
||||
|
||||
}
|
||||
delay(500);
|
||||
|
||||
mv.clear(PAGE);
|
||||
mv.setCursor(0,40);
|
||||
mv.print(" Font 0 ");
|
||||
mv.display();
|
||||
uView.clear(PAGE);
|
||||
uView.setCursor(0,40);
|
||||
uView.print(" Font 0 ");
|
||||
uView.display();
|
||||
|
||||
mv.setFontType(0);
|
||||
mv.setCursor(0,0);
|
||||
mv.print("01234567890ABCDabcd01234567890ABCDabcd");
|
||||
mv.display();
|
||||
uView.setFontType(0);
|
||||
uView.setCursor(0,0);
|
||||
uView.print("01234567890ABCDabcd01234567890ABCDabcd");
|
||||
uView.display();
|
||||
delay(1500);
|
||||
|
||||
mv.clear(PAGE);
|
||||
mv.setCursor(0,40);
|
||||
mv.print(" Font 1 ");
|
||||
mv.display();
|
||||
uView.clear(PAGE);
|
||||
uView.setCursor(0,40);
|
||||
uView.print(" Font 1 ");
|
||||
uView.display();
|
||||
|
||||
mv.setFontType(1);
|
||||
mv.setCursor(0,0);
|
||||
mv.print("0123ABCDabcd");
|
||||
mv.display();
|
||||
uView.setFontType(1);
|
||||
uView.setCursor(0,0);
|
||||
uView.print("0123ABCDabcd");
|
||||
uView.display();
|
||||
delay(1500);
|
||||
mv.clear(PAGE);
|
||||
uView.clear(PAGE);
|
||||
|
||||
counter=99999;
|
||||
while (counter>99970) {
|
||||
|
||||
if (millis()>=mSec) {
|
||||
|
||||
mv.setFontType(2);
|
||||
mv.setCursor(0,0);
|
||||
mv.print(counter);
|
||||
uView.setFontType(3);
|
||||
uView.setCursor(0,0);
|
||||
uView.print(counter);
|
||||
|
||||
counter--;
|
||||
mv.display();
|
||||
uView.display();
|
||||
mSec=millis()+100;
|
||||
}
|
||||
}
|
||||
mv.clear(PAGE);
|
||||
uView.clear(PAGE);
|
||||
|
||||
counter=19.99;
|
||||
while (counter<20.2) {
|
||||
|
||||
if (millis()>=mSec) {
|
||||
|
||||
uView.setFontType(2);
|
||||
uView.setCursor(0,0);
|
||||
uView.print(counter + ((int)(counter*100)%20));
|
||||
|
||||
uView.setCursor(0,uView.getFontHeight());
|
||||
uView.print(50-counter);
|
||||
|
||||
uView.setCursor(0,(uView.getFontHeight()*2));
|
||||
uView.print(75+counter+0.02);
|
||||
|
||||
counter+=0.01;
|
||||
uView.display();
|
||||
mSec=millis()+100;
|
||||
}
|
||||
}
|
||||
uView.clear(PAGE);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
39
examples/MicroViewSlider/MicroViewSlider.ino
Normal file
39
examples/MicroViewSlider/MicroViewSlider.ino
Normal file
@@ -0,0 +1,39 @@
|
||||
#include <SPI.h>
|
||||
#include <MicroView.h>
|
||||
|
||||
MicroViewWidget *widget[4];
|
||||
|
||||
void setup() {
|
||||
|
||||
widget[0] = new MicroViewSlider(0,0,0,100);
|
||||
widget[1] = new MicroViewSlider(0,10,0,150);
|
||||
widget[2] = new MicroViewSlider(0,20,0,50);
|
||||
widget[3] = new MicroViewSlider(0,30,0,200);
|
||||
Serial.begin(115200);
|
||||
Serial.println("start");
|
||||
uView.begin();
|
||||
uView.clear(PAGE);
|
||||
widget[0]->draw();
|
||||
widget[1]->draw();
|
||||
widget[2]->draw();
|
||||
widget[3]->draw();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
for (int i=0;i<101;i++) {
|
||||
widget[0]->setValue(i);
|
||||
widget[1]->setValue(100-i);
|
||||
widget[2]->setValue(i);
|
||||
widget[3]->setValue(100-i);
|
||||
uView.display();
|
||||
}
|
||||
|
||||
for(int i=100; i>-1;i--) {
|
||||
widget[0]->setValue(i);
|
||||
widget[1]->setValue(100-i);
|
||||
widget[2]->setValue(i);
|
||||
widget[3]->setValue(100-i);
|
||||
uView.display();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user