mirror of
https://github.com/geekammo/MicroView-Arduino-Library.git
synced 2026-02-20 03:21:30 +01:00
Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9ee0b95cf8 | ||
|
|
fb8b9c4a43 | ||
|
|
e6045dcfa1 | ||
|
|
93beac25d5 | ||
|
|
7fd29e3c92 | ||
|
|
eaf0862bb5 | ||
|
|
ec1c760c7c | ||
|
|
684a5dc5c8 | ||
|
|
8c12a660e6 | ||
|
|
af4f0bea23 | ||
|
|
7f15062e58 |
888
MicroView.cpp
888
MicroView.cpp
File diff suppressed because it is too large
Load Diff
77
MicroView.h
77
MicroView.h
@@ -8,10 +8,12 @@
|
||||
#define swap(a, b) { uint8_t t = a; a = b; b = t; }
|
||||
|
||||
#define DC 8
|
||||
#define RESET 12
|
||||
|
||||
// SS, SCK, MOSI already defined by original pins_arduino.h
|
||||
//#define CS 10
|
||||
//#define SCK 13
|
||||
//#define MOSI 11
|
||||
#define RESET 12
|
||||
//#define CS 10
|
||||
|
||||
#define BLACK 0
|
||||
#define WHITE 1
|
||||
@@ -26,6 +28,10 @@
|
||||
#define PAGE 0
|
||||
#define ALL 1
|
||||
|
||||
#define WIDGETSTYLE0 0
|
||||
#define WIDGETSTYLE1 1
|
||||
#define WIDGETSTYLE2 2
|
||||
|
||||
#define SETCONTRAST 0x81
|
||||
#define DISPLAYALLONRESUME 0xA4
|
||||
#define DISPLAYALLON 0xA5
|
||||
@@ -59,6 +65,28 @@
|
||||
#define VERTICALRIGHTHORIZONTALSCROLL 0x29
|
||||
#define VERTICALLEFTHORIZONTALSCROLL 0x2A
|
||||
|
||||
typedef enum CMD {
|
||||
CMD_CLEAR, //0
|
||||
CMD_INVERT, //1
|
||||
CMD_CONTRAST, //2
|
||||
CMD_DISPLAY, //3
|
||||
CMD_SETCURSOR, //4
|
||||
CMD_PIXEL, //5
|
||||
CMD_LINE, //6
|
||||
CMD_LINEH, //7
|
||||
CMD_LINEV, //8
|
||||
CMD_RECT, //9
|
||||
CMD_RECTFILL, //10
|
||||
CMD_CIRCLE, //11
|
||||
CMD_CIRCLEFILL, //12
|
||||
CMD_DRAWCHAR, //13
|
||||
CMD_DRAWBITMAP, //14
|
||||
CMD_GETLCDWIDTH, //15
|
||||
CMD_GETLCDHEIGHT, //16
|
||||
CMD_SETCOLOR, //17
|
||||
CMD_SETDRAWMODE //18
|
||||
} commCommand_t;
|
||||
|
||||
class MicroView : public Print{
|
||||
public:
|
||||
MicroView(void) {};
|
||||
@@ -76,10 +104,11 @@ public:
|
||||
void setColumnAddress(uint8_t add);
|
||||
void setPageAddress(uint8_t add);
|
||||
|
||||
// LCD Draw functions
|
||||
// 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);
|
||||
@@ -120,16 +149,25 @@ 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);
|
||||
void flipVertical(boolean flip);
|
||||
void flipHorizontal(boolean flip);
|
||||
|
||||
// Communication
|
||||
void checkComm(void);
|
||||
void doCmd(uint8_t index);
|
||||
|
||||
private:
|
||||
//uint8_t cs;
|
||||
volatile uint8_t *mosiport, *sckport, *ssport, *dcport; // use volatile because these are fixed location port address
|
||||
//volatile uint8_t *mosiport, *sckport;
|
||||
volatile uint8_t *ssport, *dcport, *ssreg, *dcreg; // 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[];
|
||||
|
||||
int readSerial(void);
|
||||
};
|
||||
|
||||
class MicroViewWidget {
|
||||
@@ -147,6 +185,8 @@ public:
|
||||
void setMinValue(int16_t max);
|
||||
void setValue(int16_t val);
|
||||
virtual void draw(){};
|
||||
virtual void drawFace(){};
|
||||
|
||||
private:
|
||||
uint8_t x;
|
||||
uint8_t y;
|
||||
@@ -158,13 +198,26 @@ private:
|
||||
class MicroViewSlider: public MicroViewWidget{
|
||||
public:
|
||||
MicroViewSlider(uint8_t newx, uint8_t newy, int16_t min, int16_t max);
|
||||
MicroViewSlider(uint8_t newx, uint8_t newy, int16_t min, int16_t max, uint8_t sty);
|
||||
void draw();
|
||||
void drawFace();
|
||||
private:
|
||||
uint8_t totalTicks;
|
||||
uint8_t totalTicks, style;
|
||||
bool needFirstDraw;
|
||||
int16_t prevValue;
|
||||
};
|
||||
|
||||
class MicroViewGauge: public MicroViewWidget{
|
||||
public:
|
||||
MicroViewGauge(uint8_t newx, uint8_t newy, int16_t min, int16_t max);
|
||||
MicroViewGauge(uint8_t newx, uint8_t newy, int16_t min, int16_t max, uint8_t sty);
|
||||
void draw();
|
||||
void drawFace();
|
||||
private:
|
||||
uint8_t radius, style;
|
||||
bool needFirstDraw;
|
||||
int16_t prevValue;
|
||||
};
|
||||
|
||||
#define SPI_CLOCK_DIV4 0x00
|
||||
#define SPI_CLOCK_DIV16 0x01
|
||||
@@ -184,7 +237,7 @@ private:
|
||||
#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 {
|
||||
class MVSPIClass {
|
||||
public:
|
||||
inline static byte transfer(byte _data);
|
||||
|
||||
@@ -201,20 +254,20 @@ public:
|
||||
static void setClockDivider(uint8_t);
|
||||
};
|
||||
|
||||
extern SPIClass MVSPI;
|
||||
extern MVSPIClass MVSPI;
|
||||
|
||||
byte SPIClass::transfer(byte _data) {
|
||||
byte MVSPIClass::transfer(byte _data) {
|
||||
SPDR = _data;
|
||||
while (!(SPSR & _BV(SPIF)))
|
||||
;
|
||||
return SPDR;
|
||||
}
|
||||
|
||||
void SPIClass::attachInterrupt() {
|
||||
void MVSPIClass::attachInterrupt() {
|
||||
SPCR |= _BV(SPIE);
|
||||
}
|
||||
|
||||
void SPIClass::detachInterrupt() {
|
||||
void MVSPIClass::detachInterrupt() {
|
||||
SPCR &= ~_BV(SPIE);
|
||||
}
|
||||
|
||||
|
||||
94
README.md
94
README.md
@@ -12,17 +12,35 @@ Arduino library for MicroView.
|
||||
|
||||
## Installation
|
||||
|
||||
1. Extract / Check out to Arduino's libraries folder.
|
||||
2. Start Arduino IDE.
|
||||
3. MicroView example is located at, File--->Example--->MicroView--->MicroViewDemo
|
||||
1. Change directory to Arduino's main directory
|
||||
2. cd libraries
|
||||
3. mkdir MicroView
|
||||
4. cd MicroView
|
||||
5. git clone git@github.com:geekammo/microview.git .
|
||||
6. Start Arduino IDE.
|
||||
7. MicroView example is located at, File--->Example--->MicroView--->MicroViewDemo
|
||||
|
||||
### Example
|
||||
### Example 1 - Hello World!
|
||||
<pre><code>
|
||||
#include <MicroView.h>
|
||||
|
||||
void setup() {
|
||||
uView.begin();
|
||||
uView.clear(PAGE); // clear the page buffer
|
||||
}
|
||||
|
||||
void loop() {
|
||||
uView.print("HelloWorld");
|
||||
uView.display(); // display current page buffer
|
||||
}
|
||||
</code></pre>
|
||||
|
||||
### Example 2 - Basic Drawing
|
||||
<pre><code>
|
||||
#include <MicroView.h>
|
||||
|
||||
void setup() {
|
||||
uView.begin();
|
||||
uView.clear(PAGE); // clear the page buffer
|
||||
}
|
||||
|
||||
void loop() {
|
||||
@@ -32,12 +50,70 @@ void loop() {
|
||||
uView.pixel(50,5);
|
||||
uView.setCursor(0,40);
|
||||
uView.print(" MicroView");
|
||||
uView.display(); // display current page buffer
|
||||
uView.display(); // display current page buffer
|
||||
}
|
||||
</code></pre>
|
||||
|
||||
### Example 3 - Widgets
|
||||
<pre><code>
|
||||
#include <MicroView.h>
|
||||
|
||||
MicroViewWidget *widget,*widget2;
|
||||
|
||||
void setup() {
|
||||
uView.begin();
|
||||
uView.clear(PAGE);
|
||||
widget= new MicroViewGauge(32,30,0,100); // draw Gauge widget at x=32,y=30,min=0, max=100
|
||||
widget2= new MicroViewSlider(0,0,0,100); // draw Slider widget at x=0,y=0,min=0, max=100
|
||||
}
|
||||
|
||||
void loop() {
|
||||
for(int i=0; i<=100;i++) {
|
||||
widget->setValue(i); // give a value to widget
|
||||
widget2->setValue(i);
|
||||
uView.display(); // display current page buffer
|
||||
}
|
||||
}
|
||||
</code></pre>
|
||||
|
||||
### Example 4 - Communication
|
||||
<pre><code>
|
||||
#include <MicroView.h>
|
||||
|
||||
void setup() {
|
||||
uView.begin();
|
||||
uView.clear(PAGE);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
uView.checkComm();
|
||||
}
|
||||
</code></pre>
|
||||
|
||||
## History
|
||||
**v1.05b: 6th February by JP Liew**
|
||||
**v1.10b: 22th April 2014 by JP Liew**
|
||||
* changed SS, RESET, DC pins to use weak internal pull-up resistors
|
||||
|
||||
**v1.09b: 17th April 2014 by JP Liew**
|
||||
* changed verticalFlip() to flipVertical() and horizontalFlip() to flipHorizontal() for consistency
|
||||
* added debug messages for doCmd()
|
||||
|
||||
**v1.08b: 18th February 2014 by JP Liew**
|
||||
* added verticalFlip(), horizontalFlip()
|
||||
|
||||
**v1.07b: 15th February 2014 by JP Liew**
|
||||
* changed function name stopScroll to scrollStop for consistency
|
||||
* added contrast function
|
||||
* added invert function
|
||||
* added KEYWORD to keywords.txt
|
||||
* added checkComm() function to communicate with host PC
|
||||
|
||||
**v1.06b: 9th February 2014 by JP Liew**
|
||||
* fixed Slider negative value not working
|
||||
* added round Gauge widget
|
||||
* changed Example 3 to show round Gauge
|
||||
|
||||
**v1.05b: 6th February 2014 by JP Liew**
|
||||
* changed MICROVIEW class name to MicroView
|
||||
* created MICROVIEWWIDGET class
|
||||
* added routines to draw widget
|
||||
@@ -45,7 +121,6 @@ void loop() {
|
||||
* merged MicroViewWidget into MicroView
|
||||
* merged SPI.h into MicroView
|
||||
|
||||
|
||||
**v1.04b: 3rd February 2014 by JP Liew**
|
||||
* declared permanent uView variable.
|
||||
* cleaned code and added some remarks.
|
||||
@@ -63,5 +138,4 @@ void loop() {
|
||||
* added analog clock demo.
|
||||
|
||||
**v1.00b: 30th January 2014 by JP Liew**
|
||||
* Initial commit. Beta with minor bugs.
|
||||
|
||||
* Initial commit. Beta with minor bugs.
|
||||
@@ -1,18 +1,17 @@
|
||||
#include <MicroView.h>
|
||||
#include <Time.h>
|
||||
|
||||
//#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);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,39 +1,30 @@
|
||||
#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();
|
||||
}
|
||||
|
||||
#include <MicroView.h>
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
59
keywords.txt
59
keywords.txt
@@ -7,18 +7,75 @@
|
||||
#######################################
|
||||
|
||||
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
|
||||
flipVertical KEYWORD2
|
||||
flipHorizontal KEYWORD2
|
||||
|
||||
getX KEYWORD2
|
||||
getY KEYWORD2
|
||||
setX KEYWORD2
|
||||
setY KEYWORD2
|
||||
getMinValue KEYWORD2
|
||||
getMaxValue KEYWORD2
|
||||
setMaxValue KEYWORD2
|
||||
setMinValue KEYWORD2
|
||||
setValue KEYWORD2
|
||||
draw KEYWORD2
|
||||
drawFace KEYWORD2
|
||||
checkComm KEYWORD2
|
||||
|
||||
#######################################
|
||||
# Constants (LITERAL1)
|
||||
#######################################
|
||||
|
||||
BLACK LITERAL1
|
||||
WHITE LITERAL1
|
||||
NORM LITERAL1
|
||||
XOR LITERAL1
|
||||
PAGE LITERAL1
|
||||
ALL LITERAL1
|
||||
WIDGETSTYLE0 LITERAL1
|
||||
WIDGETSTYLE1 LITERAL1
|
||||
WIDGETSTYLE2 LITERAL1
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user