Skip to content

Commit eaf0862

Browse files
committed
added invert function, contrast function, changed scrollStop to scrollStop for consistency
1 parent ec1c760 commit eaf0862

File tree

6 files changed

+122
-56
lines changed

6 files changed

+122
-56
lines changed

MicroView.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,18 @@ void MicroView::clear(uint8_t mode, uint8_t c) {
233233
}
234234
}
235235

236+
void MicroView::invert(boolean inv) {
237+
if (inv)
238+
command(INVERTDISPLAY);
239+
else
240+
command(NORMALDISPLAY);
241+
}
242+
243+
void MicroView::contrast(uint8_t contrast) {
244+
command(SETCONTRAST); // 0x81
245+
command(contrast);
246+
}
247+
236248
// This routine is to transfer the page buffer to the LCD controller's memory.
237249
void MicroView::display(void) {
238250
uint8_t i, j;
@@ -633,14 +645,14 @@ size_t MicroView::write(uint8_t c) {
633645

634646
}
635647

636-
void MicroView::stopScroll(void){
648+
void MicroView::scrollStop(void){
637649
command(DEACTIVATESCROLL);
638650
}
639651

640652
void MicroView::scrollRight(uint8_t start, uint8_t stop){
641653
if (stop<start) // stop must be larger or equal to start
642654
return;
643-
stopScroll(); // need to disable scrolling before starting to avoid memory corrupt
655+
scrollStop(); // need to disable scrolling before starting to avoid memory corrupt
644656
command(RIGHTHORIZONTALSCROLL);
645657
command(0x00);
646658
command(start);
@@ -679,8 +691,9 @@ size_t MicroView::write(uint8_t c) {
679691

680692
void MicroViewWidget::setMinValue(int16_t min) { minValue=min; }
681693
void MicroViewWidget::setMaxValue(int16_t max) { maxValue=max; }
694+
682695
void MicroViewWidget::setValue(int16_t val) {
683-
if (val<=maxValue) {
696+
if ((val<=maxValue) && (val>=minValue)){
684697
value=val;
685698
this->draw();
686699
}

MicroView.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@
6464
#define VERTICALRIGHTHORIZONTALSCROLL 0x29
6565
#define VERTICALLEFTHORIZONTALSCROLL 0x2A
6666

67+
typedef enum CMD {CMD_CLEAR,CMD_INVERT,CMD_CONTRAST,CMD_DISPLAY,CMD_SETCURSOR,CMD_PIXEL,CMD_LINE,
68+
CMD_LINEH,CMD_LINEV,CMD_RECT, CMD_RECTFILL, CMD_CIRCLE,CMD_CIRCLEFILL, CMD_DRAWCHAR, CMD_DRAWBITMAP,
69+
CMD_GETLCDWIDTH, CMD_GETLCDHEIGHT,CMD_SETCOLOR, CMD_SETDRAWMODE} commCommand_t;
70+
6771
class MicroView : public Print{
6872
public:
6973
MicroView(void) {};
@@ -84,7 +88,8 @@ class MicroView : public Print{
8488
// LCD Draw functions
8589
void clear(uint8_t mode);
8690
void clear(uint8_t mode, uint8_t c);
87-
void invert(uint8_t i);
91+
void invert(boolean inv);
92+
void contrast(uint8_t contrast);
8893
void display(void);
8994
void setCursor(uint8_t x, uint8_t y);
9095
void pixel(uint8_t x, uint8_t y);
@@ -125,7 +130,7 @@ class MicroView : public Print{
125130
void scrollLeft(uint8_t start, uint8_t stop);
126131
void scrollVertRight(uint8_t start, uint8_t stop);
127132
void scrollVertLeft(uint8_t start, uint8_t stop);
128-
void stopScroll(void);
133+
void scrollStop(void);
129134

130135
private:
131136
//uint8_t cs;

README.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Arduino library for MicroView.
1616
2. Start Arduino IDE.
1717
3. MicroView example is located at, File--->Example--->MicroView--->MicroViewDemo
1818

19-
### Example 1
19+
### Example 1 - Hello World!
2020
<pre><code>
2121
#include &lt;MicroView.h&gt;
2222

@@ -30,7 +30,7 @@ void loop() {
3030
}
3131
</code></pre>
3232

33-
### Example 2
33+
### Example 2 - Basic Drawing
3434
<pre><code>
3535
#include &lt;MicroView.h&gt;
3636

@@ -50,7 +50,7 @@ void loop() {
5050
}
5151
</code></pre>
5252

53-
### Example 3
53+
### Example 3 - Widgets
5454
<pre><code>
5555
#include &lt;MicroView.h&gt;
5656

@@ -73,7 +73,13 @@ void loop() {
7373
</code></pre>
7474

7575
## History
76-
**v1.06b: by JP Liew**
76+
**v1.07b: 10th February by JP Liew**
77+
* changed function name stopScroll to scrollStop for consistency
78+
* added contrast function
79+
* added invert function
80+
* added KEYWORD to keywords.txt
81+
82+
**v1.06b: 9th February by JP Liew**
7783
* fixed Slider negative value not working
7884
* added round Gauge widget
7985
* changed Example 3 to show round Gauge

examples/MicroViewDemo/MicroViewDemo.ino

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
#include <MicroView.h>
22
#include <Time.h>
33

4-
//#define PI 3.141592654
54
#define clocksize 24
65

7-
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.
6+
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.
87

98
void setup() {
10-
uView.begin(); // Begin of MicroView
11-
uView.clear(ALL); // Erase hardware memory inside the OLED controller
12-
uView.display(); // Display the content in the buffer memory, by default it is the MicroView logo
9+
uView.begin(); // begin of MicroView
10+
uView.clear(ALL); // erase hardware memory inside the OLED controller
11+
uView.display(); // display the content in the buffer memory, by default it is the MicroView logo
1312
setTime(10,10,01,17,1,2014);
1413
delay(500);
15-
uView.clear(PAGE); // Erase the memory buffer, when next uView.display() is called, the OLED will be cleared.
14+
uView.clear(PAGE); // erase the memory buffer, when next uView.display() is called, the OLED will be cleared.
1615
}
1716

1817
void loop() {
@@ -261,8 +260,6 @@ void loop() {
261260
}
262261
}
263262
uView.clear(PAGE);
264-
265-
266263
}
267264

268265

Lines changed: 29 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,30 @@
1-
#include <SPI.h>
2-
#include <MicroView.h>
3-
4-
MicroViewWidget *widget[4];
5-
6-
void setup() {
7-
8-
widget[0] = new MicroViewSlider(0,0,0,100);
9-
widget[1] = new MicroViewSlider(0,10,0,150);
10-
widget[2] = new MicroViewSlider(0,20,0,50);
11-
widget[3] = new MicroViewSlider(0,30,0,200);
12-
Serial.begin(115200);
13-
Serial.println("start");
14-
uView.begin();
15-
uView.clear(PAGE);
16-
widget[0]->draw();
17-
widget[1]->draw();
18-
widget[2]->draw();
19-
widget[3]->draw();
20-
}
21-
22-
void loop() {
23-
for (int i=0;i<101;i++) {
24-
widget[0]->setValue(i);
25-
widget[1]->setValue(100-i);
26-
widget[2]->setValue(i);
27-
widget[3]->setValue(100-i);
28-
uView.display();
29-
}
30-
31-
for(int i=100; i>-1;i--) {
32-
widget[0]->setValue(i);
33-
widget[1]->setValue(100-i);
34-
widget[2]->setValue(i);
35-
widget[3]->setValue(100-i);
36-
uView.display();
37-
}
38-
1+
#include <MicroView.h>
2+
3+
MicroViewWidget *widget[4]; // declaring an array of 4 MicroViewWidget
4+
5+
void setup() {
6+
uView.begin(); // init and start MicroView
7+
uView.clear(PAGE); // erase the memory buffer, when next uView.display() is called, the OLED will be cleared.
8+
widget[0] = new MicroViewSlider(0,0,0,100); // declare widget0 as a Slider at x=0, y=0, min=0, max=100
9+
widget[1] = new MicroViewSlider(0,10,0,150); // declare widget0 as a Slider at x=0, y=10, min=0, max=150
10+
widget[2] = new MicroViewSlider(0,20,0,50); // declare widget0 as a Slider at x=0, y=20, min=0, max=50
11+
widget[3] = new MicroViewSlider(0,30,0,200); // declare widget0 as a Slider at x=0, y=30, min=0, max=200
12+
}
13+
14+
void loop() {
15+
for (int i=0;i<=100;i++) {
16+
widget[0]->setValue(i); // set value i to widget0
17+
widget[1]->setValue(100-i);
18+
widget[2]->setValue(i);
19+
widget[3]->setValue(100-i);
20+
uView.display();
21+
}
22+
23+
for(int i=100; i>=0;i--) {
24+
widget[0]->setValue(i);
25+
widget[1]->setValue(100-i);
26+
widget[2]->setValue(i);
27+
widget[3]->setValue(100-i);
28+
uView.display();
29+
}
3930
}

keywords.txt

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,72 @@
77
#######################################
88

99
MICROVIEW KEYWORD1
10+
uView KEYWORD1
11+
MicroViewWidget KEYWORD1
12+
MicroViewSlider KEYWORD1
13+
MicroViewGauge KEYWORD1
1014

1115
#######################################
1216
# Methods and Functions (KEYWORD2)
1317
#######################################
1418

1519
begin KEYWORD2
20+
invert KEYWORD2
1621
clear KEYWORD2
17-
home KEYWORD2
22+
invert KEYWORD2
23+
contrast KEYWORD2
1824
display KEYWORD2
25+
setCursor KEYWORD2
26+
pixel KEYWORD2
27+
line KEYWORD2
28+
lineH KEYWORD2
29+
lineV KEYWORD2
30+
rect KEYWORD2
31+
rectFill KEYWORD2
32+
circle KEYWORD2
33+
circleFill KEYWORD2
34+
drawChar KEYWORD2
35+
getLCDWidth KEYWORD2
36+
getLCDHeight KEYWORD2
37+
setColor KEYWORD2
38+
setDrawMode KEYWORD2
39+
getFontWidth KEYWORD2
40+
getFontHeight KEYWORD2
41+
getTotalFonts KEYWORD2
42+
getFontType KEYWORD2
43+
setFontType KEYWORD2
44+
getFontStartChar KEYWORD2
45+
getFontTotalChar KEYWORD2
46+
scrollRight KEYWORD2
47+
scrollLeft KEYWORD2
48+
scrollVertRight KEYWORD2
49+
scrollVertLeft KEYWORD2
50+
scrollStop KEYWORD2
1951

52+
getX KEYWORD2
53+
getY KEYWORD2
54+
setX KEYWORD2
55+
setY KEYWORD2
56+
getMinValue KEYWORD2
57+
getMaxValue KEYWORD2
58+
setMaxValue KEYWORD2
59+
setMinValue KEYWORD2
60+
setValue KEYWORD2
61+
draw KEYWORD2
62+
drawFace KEYWORD2
2063

2164
#######################################
2265
# Constants (LITERAL1)
2366
#######################################
2467

68+
BLACK LITERAL1
69+
WHITE LITERAL1
70+
NORM LITERAL1
71+
XOR LITERAL1
72+
PAGE LITERAL1
73+
ALL LITERAL1
74+
WIDGETSTYLE0 LITERAL1
75+
WIDGETSTYLE1 LITERAL1
76+
WIDGETSTYLE2 LITERAL1
77+
78+

0 commit comments

Comments
 (0)