From eaf0862bb507551e86b760d51aeae7cabf4a2d11 Mon Sep 17 00:00:00 2001 From: JP Date: Tue, 11 Feb 2014 19:43:01 +1100 Subject: [PATCH] added invert function, contrast function, changed scrollStop to scrollStop for consistency --- MicroView.cpp | 19 +++++- MicroView.h | 9 ++- README.md | 14 ++-- examples/MicroViewDemo/MicroViewDemo.ino | 13 ++-- examples/MicroViewSlider/MicroViewSlider.ino | 67 +++++++++----------- keywords.txt | 56 +++++++++++++++- 6 files changed, 122 insertions(+), 56 deletions(-) diff --git a/MicroView.cpp b/MicroView.cpp index 75deb77..3875064 100644 --- a/MicroView.cpp +++ b/MicroView.cpp @@ -233,6 +233,18 @@ void MicroView::clear(uint8_t mode, uint8_t c) { } } +void MicroView::invert(boolean inv) { + if (inv) + command(INVERTDISPLAY); + else + command(NORMALDISPLAY); +} + +void MicroView::contrast(uint8_t contrast) { + command(SETCONTRAST); // 0x81 + command(contrast); +} + // This routine is to transfer the page buffer to the LCD controller's memory. void MicroView::display(void) { uint8_t i, j; @@ -633,14 +645,14 @@ size_t MicroView::write(uint8_t c) { } - void MicroView::stopScroll(void){ + void MicroView::scrollStop(void){ command(DEACTIVATESCROLL); } void MicroView::scrollRight(uint8_t start, uint8_t stop){ if (stop=minValue)){ value=val; this->draw(); } diff --git a/MicroView.h b/MicroView.h index d6d53ae..d44f722 100644 --- a/MicroView.h +++ b/MicroView.h @@ -64,6 +64,10 @@ #define VERTICALRIGHTHORIZONTALSCROLL 0x29 #define VERTICALLEFTHORIZONTALSCROLL 0x2A +typedef enum CMD {CMD_CLEAR,CMD_INVERT,CMD_CONTRAST,CMD_DISPLAY,CMD_SETCURSOR,CMD_PIXEL,CMD_LINE, +CMD_LINEH,CMD_LINEV,CMD_RECT, CMD_RECTFILL, CMD_CIRCLE,CMD_CIRCLEFILL, CMD_DRAWCHAR, CMD_DRAWBITMAP, +CMD_GETLCDWIDTH, CMD_GETLCDHEIGHT,CMD_SETCOLOR, CMD_SETDRAWMODE} commCommand_t; + class MicroView : public Print{ public: MicroView(void) {}; @@ -84,7 +88,8 @@ public: // LCD Draw functions void clear(uint8_t mode); void clear(uint8_t mode, uint8_t c); - void invert(uint8_t i); + void invert(boolean inv); + void contrast(uint8_t contrast); void display(void); void setCursor(uint8_t x, uint8_t y); void pixel(uint8_t x, uint8_t y); @@ -125,7 +130,7 @@ public: void scrollLeft(uint8_t start, uint8_t stop); void scrollVertRight(uint8_t start, uint8_t stop); void scrollVertLeft(uint8_t start, uint8_t stop); - void stopScroll(void); + void scrollStop(void); private: //uint8_t cs; diff --git a/README.md b/README.md index bfc6e5a..14f729a 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ Arduino library for MicroView. 2. Start Arduino IDE. 3. MicroView example is located at, File--->Example--->MicroView--->MicroViewDemo -### Example 1 +### Example 1 - Hello World!

 #include <MicroView.h>
 
@@ -30,7 +30,7 @@ void loop() {
 }
 
-### Example 2 +### Example 2 - Basic Drawing

 #include <MicroView.h>
 
@@ -50,7 +50,7 @@ void loop() {
 }
 
-### Example 3 +### Example 3 - Widgets

 #include <MicroView.h>
 
@@ -73,7 +73,13 @@ void loop() {
 
## History -**v1.06b: by JP Liew** +**v1.07b: 10th February by JP Liew** +* changed function name stopScroll to scrollStop for consistency +* added contrast function +* added invert function +* added KEYWORD to keywords.txt + +**v1.06b: 9th February by JP Liew** * fixed Slider negative value not working * added round Gauge widget * changed Example 3 to show round Gauge diff --git a/examples/MicroViewDemo/MicroViewDemo.ino b/examples/MicroViewDemo/MicroViewDemo.ino index d7073bb..5766bc3 100644 --- a/examples/MicroViewDemo/MicroViewDemo.ino +++ b/examples/MicroViewDemo/MicroViewDemo.ino @@ -1,18 +1,17 @@ #include #include -//#define PI 3.141592654 #define clocksize 24 -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. +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() { - 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 + 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); - uView.clear(PAGE); // Erase the memory buffer, when next uView.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() { @@ -261,8 +260,6 @@ void loop() { } } uView.clear(PAGE); - - } diff --git a/examples/MicroViewSlider/MicroViewSlider.ino b/examples/MicroViewSlider/MicroViewSlider.ino index 8b2c7a1..3e295bf 100644 --- a/examples/MicroViewSlider/MicroViewSlider.ino +++ b/examples/MicroViewSlider/MicroViewSlider.ino @@ -1,39 +1,30 @@ -#include -#include - -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(); - } - +#include + +MicroViewWidget *widget[4]; // declaring an array of 4 MicroViewWidget + +void setup() { + uView.begin(); // init and start MicroView + uView.clear(PAGE); // erase the memory buffer, when next uView.display() is called, the OLED will be cleared. + widget[0] = new MicroViewSlider(0,0,0,100); // declare widget0 as a Slider at x=0, y=0, min=0, max=100 + widget[1] = new MicroViewSlider(0,10,0,150); // declare widget0 as a Slider at x=0, y=10, min=0, max=150 + widget[2] = new MicroViewSlider(0,20,0,50); // declare widget0 as a Slider at x=0, y=20, min=0, max=50 + widget[3] = new MicroViewSlider(0,30,0,200); // declare widget0 as a Slider at x=0, y=30, min=0, max=200 +} + +void loop() { + for (int i=0;i<=100;i++) { + widget[0]->setValue(i); // set value i to widget0 + widget[1]->setValue(100-i); + widget[2]->setValue(i); + widget[3]->setValue(100-i); + uView.display(); + } + + for(int i=100; i>=0;i--) { + widget[0]->setValue(i); + widget[1]->setValue(100-i); + widget[2]->setValue(i); + widget[3]->setValue(100-i); + uView.display(); + } } diff --git a/keywords.txt b/keywords.txt index 88bc248..9cf6bb7 100644 --- a/keywords.txt +++ b/keywords.txt @@ -7,18 +7,72 @@ ####################################### MICROVIEW KEYWORD1 +uView KEYWORD1 +MicroViewWidget KEYWORD1 +MicroViewSlider KEYWORD1 +MicroViewGauge KEYWORD1 ####################################### # Methods and Functions (KEYWORD2) ####################################### begin KEYWORD2 +invert KEYWORD2 clear KEYWORD2 -home KEYWORD2 +invert KEYWORD2 +contrast KEYWORD2 display KEYWORD2 +setCursor KEYWORD2 +pixel KEYWORD2 +line KEYWORD2 +lineH KEYWORD2 +lineV KEYWORD2 +rect KEYWORD2 +rectFill KEYWORD2 +circle KEYWORD2 +circleFill KEYWORD2 +drawChar KEYWORD2 +getLCDWidth KEYWORD2 +getLCDHeight KEYWORD2 +setColor KEYWORD2 +setDrawMode KEYWORD2 +getFontWidth KEYWORD2 +getFontHeight KEYWORD2 +getTotalFonts KEYWORD2 +getFontType KEYWORD2 +setFontType KEYWORD2 +getFontStartChar KEYWORD2 +getFontTotalChar KEYWORD2 +scrollRight KEYWORD2 +scrollLeft KEYWORD2 +scrollVertRight KEYWORD2 +scrollVertLeft KEYWORD2 +scrollStop KEYWORD2 +getX KEYWORD2 +getY KEYWORD2 +setX KEYWORD2 +setY KEYWORD2 +getMinValue KEYWORD2 +getMaxValue KEYWORD2 +setMaxValue KEYWORD2 +setMinValue KEYWORD2 +setValue KEYWORD2 +draw KEYWORD2 +drawFace KEYWORD2 ####################################### # Constants (LITERAL1) ####################################### +BLACK LITERAL1 +WHITE LITERAL1 +NORM LITERAL1 +XOR LITERAL1 +PAGE LITERAL1 +ALL LITERAL1 +WIDGETSTYLE0 LITERAL1 +WIDGETSTYLE1 LITERAL1 +WIDGETSTYLE2 LITERAL1 + +