Permalink
Browse files

fixed flakiness by adding missing delay() after clearing display, the…

…n fixed sluggishness - not terrible anymore
  • Loading branch information...
1 parent ec5cfe6 commit efc28622fe6432335527c6187c3c81efe1f8cbae @ladyada ladyada committed Mar 16, 2012
Showing with 444 additions and 612 deletions.
  1. +163 −142 Adafruit_GP9002.cpp
  2. +16 −10 Adafruit_GP9002.h
  3. +0 −148 Adafruit_MonoGfx.cpp
  4. +0 −46 Adafruit_MonoGfx.h
  5. +265 −0 examples/GraphicVFDtest/GraphicVFDtest.pde
  6. +0 −266 glcdfont.c
View
305 Adafruit_GP9002.cpp
@@ -2,14 +2,10 @@
#include <util/delay.h>
#include <stdlib.h>
+#include "Adafruit_GFX.h"
#include "Adafruit_GP9002.h"
#include "glcdfont.c"
-static uint8_t is_reversed = 0;
-
-// a 5x7 font table
-extern uint8_t PROGMEM font[];
-
Adafruit_GP9002::Adafruit_GP9002(int8_t SCLK, int8_t MISO, int8_t MOSI,
int8_t CS, int8_t DC) {
_sclk = SCLK;
@@ -18,203 +14,226 @@ Adafruit_GP9002::Adafruit_GP9002(int8_t SCLK, int8_t MISO, int8_t MOSI,
_cs = CS;
_dc = DC;
- WIDTH = 128;
- HEIGHT = 64;
+ constructor(128, 64);
}
+void Adafruit_GP9002::begin(void) {
+ // set pin directions
+ pinMode(_mosi, OUTPUT);
+ pinMode(_miso, INPUT);
+ pinMode(_sclk, OUTPUT);
+ pinMode(_dc, OUTPUT);
+ pinMode(_cs, OUTPUT);
-void Adafruit_GP9002::drawString(uint8_t x, uint8_t line, char *c) {
- while (c[0] != 0) {
- drawChar(x, line, c[0]);
- c++;
- x += 6; // 6 pixels wide
- if (x + 6 >= this->WIDTH) {
- x = 0; // ran out of this line
- line++;
- }
- if (line >= (this->HEIGHT/8))
- return; // ran out of space :(
- }
+ clkport = portOutputRegister(digitalPinToPort(_sclk));
+ clkpinmask = digitalPinToBitMask(_sclk);
+ mosiport = portOutputRegister(digitalPinToPort(_mosi));
+ mosipinmask = digitalPinToBitMask(_mosi);
+ csport = portOutputRegister(digitalPinToPort(_cs));
+ cspinmask = digitalPinToBitMask(_cs);
+ dcport = portOutputRegister(digitalPinToPort(_dc));
+ dcpinmask = digitalPinToBitMask(_dc);
+ misopin = portInputRegister(digitalPinToPort(_miso));
+ misopinmask = digitalPinToBitMask(_miso);
-}
+ command(GP9002_DISPLAY);
+ dataWrite(GP9002_DISPLAY_MONOCHROME);
+ command(GP9002_LOWERADDR1);
+ dataWrite(0x0);
+ command(GP9002_HIGHERADDR1);
+ dataWrite(0x0);
+ command(GP9002_LOWERADDR2);
+ dataWrite(0x0);
+ command(GP9002_HIGHERADDR2);
+ dataWrite(0x4);
+ command(GP9002_OR);
+ command(GP9002_CLEARSCREEN);
+ command(GP9002_DISPLAY1ON);
-void Adafruit_GP9002::drawChar(uint8_t x, uint8_t line, uint8_t c) {
- if ((line >= this->HEIGHT/8) || (x >= (this->WIDTH - 6)))
- return;
- for (uint8_t i =0; i<5; i++ ) {
- //buffer[x + (line*128) ] = pgm_read_byte(font+(c*5)+i);
- x++;
- }
+ // hold the address so we can read and then write
+ command(GP9002_ADDRHELD);
}
+
// updated high speed drawing!
-void Adafruit_GP9002::drawFastVLine(uint8_t x, uint8_t orig_y, uint8_t h, uint8_t color) {
-
- while (orig_y % 8) {
+void Adafruit_GP9002::drawFastVLine(uint16_t x, uint16_t orig_y, uint16_t h, uint16_t color) {
+
+ while (h && (orig_y % 8)) {
drawPixel(x, orig_y, color);
orig_y++;
h--;
}
-
- // calculate addr
- uint16_t addr = 0;
- addr = x*8;
- addr += orig_y/8;
-
- command(GP9002_ADDRINCR);
- command(GP9002_ADDRL);
- data(addr & 0xFF);
- command(GP9002_ADDRH);
- data(addr >> 8);
- command(GP9002_DATAWRITE);
- while (h >= 8) {
- // draw 8 pixels at once!
- if (color)
- data(0xFF);
- else
- data(0x00);
- h -= 8;
- orig_y += 8;
- }
- command(GP9002_ADDRHELD);
+ if (h >= 8) {
+ // calculate addr
+ uint16_t addr = 0;
+ addr = x*8;
+ addr += orig_y/8;
+
+ command(GP9002_ADDRINCR);
+ command(GP9002_ADDRL);
+ dataWrite(addr & 0xFF);
+ command(GP9002_ADDRH);
+ dataWrite(addr >> 8);
+ command(GP9002_DATAWRITE);
+
+ *dcport &= ~dcpinmask;
+ *csport &= ~cspinmask;
+ while (h >= 8) {
+ // draw 8 pixels at once!
+ if (color)
+ fastSPIwrite(0xFF);
+ else
+ fastSPIwrite(0);
+ h -= 8;
+ orig_y += 8;
+ }
+ *csport |= cspinmask;
+ command(GP9002_ADDRHELD);
+ }
+
while (h) {
drawPixel(x, orig_y, color);
orig_y++;
h--;
}
}
-
-
-
-
-
// the most basic function, set a single pixel
-void Adafruit_GP9002::drawPixel(uint8_t x, uint8_t y, uint8_t color) {
- if ((x >= this->WIDTH) || (y >= this->HEIGHT))
+void Adafruit_GP9002::drawPixel(uint16_t x, uint16_t y, uint16_t color) {
+ if ((x >= width()) || (y >= height()))
return;
uint8_t p;
// calculate addr
uint16_t addr = 0;
addr = x*8;
+ y = 63 - y;
addr += y/8;
- // hold the address so we can read and then write
- command(GP9002_ADDRHELD);
-
command(GP9002_ADDRL);
- data(addr & 0xFF);
+ dataWrite(addr & 0xFF);
command(GP9002_ADDRH);
- data(addr >> 8);
-
+ dataWrite(addr >> 8);
command(GP9002_DATAREAD);
- data(0x0);
- p = data(0x0);
-
- p |= (1 << (7-(y % 8)));
+ dataRead();
+ p = dataRead();
+
+ if (color)
+ p |= (1 << (7-(y % 8)));
+ else
+ p &= ~(1 << (7-(y % 8)));
command(GP9002_DATAWRITE);
- data(p);
+ dataWrite(p);
}
-void Adafruit_GP9002::begin(void) {
- // set pin directions
- pinMode(_mosi, OUTPUT);
- pinMode(_miso, INPUT);
- pinMode(_sclk, OUTPUT);
- pinMode(_dc, OUTPUT);
- pinMode(_cs, OUTPUT);
- command(GP9002_DISPLAY);
- data(GP9002_DISPLAY_MONOCHROME);
- command(GP9002_OR);
- command(GP9002_CLEARSCREEN);
- command(GP9002_DISPLAY1ON);
-}
-
-
-void Adafruit_GP9002::invert(uint8_t i) {
- // command(GP9002_XOR);
-}
-
-uint8_t Adafruit_GP9002::spiTransfer(uint8_t d, uint8_t datacommand) {
- uint8_t reply = 0;
+void Adafruit_GP9002::invert(boolean i) {
+ // This is kinda clumsy but it does work
+ // fill the opposite screen with all on pixels so we can invert!
+ uint16_t addr = 0x400;
- volatile uint8_t *sclkportreg, *mosiportreg, *misoportreg;
- uint8_t sclkpin, mosipin, misopin;
+ command(GP9002_ADDRINCR);
+ command(GP9002_ADDRL);
+ dataWrite(addr & 0xFF);
+ command(GP9002_ADDRH);
+ dataWrite(addr >> 8);
+ command(GP9002_DATAWRITE);
- digitalWrite(_dc, datacommand);
- digitalWrite(_cs, LOW);
+ if (i) {
+ while (addr < 0x0800) {
+ dataWrite(0xFF);
+ addr++;
+ }
+ command(GP9002_XOR);
+ } else {
+ while (addr < 0x0800) {
+ dataWrite(0x00);
+ addr++;
+ }
+ command(GP9002_OR);
+ }
+ command(GP9002_ADDRHELD);
- sclkportreg = portOutputRegister(digitalPinToPort(_sclk));
- sclkpin = digitalPinToBitMask(_sclk);
- mosiportreg = portOutputRegister(digitalPinToPort(_mosi));
- mosipin = digitalPinToBitMask(_mosi);
- misoportreg = portInputRegister(digitalPinToPort(_miso));
- misopin = digitalPinToBitMask(_miso);
+}
+void Adafruit_GP9002::slowSPIwrite(uint8_t d) {
for (uint8_t i=0; i<8; i++) {
- //digitalWrite(_sclk, LOW);
- *sclkportreg &= ~sclkpin;
+ digitalWrite(_sclk, LOW);
if (d & _BV(i)) {
- //digitalWrite(_mosi, HIGH);
- *mosiportreg |= mosipin;
+ digitalWrite(_mosi, HIGH);
} else {
- //digitalWrite(_mosi, LOW);
- *mosiportreg &= ~mosipin;
+ digitalWrite(_mosi, LOW);
}
- //delayMicroseconds(10);
- //digitalWrite(_sclk, HIGH);
- *sclkportreg |= sclkpin;
+ digitalWrite(_sclk, HIGH);
+ }
+}
+inline void Adafruit_GP9002::fastSPIwrite(uint8_t d) {
+ for(uint8_t bit = 0x1; bit != 0x00; bit <<= 1) {
+ *clkport &= ~clkpinmask;
+ if(d & bit) *mosiport |= mosipinmask;
+ else *mosiport &= ~mosipinmask;
+ *clkport |= clkpinmask;
+ }
+}
+
+uint8_t Adafruit_GP9002::slowSPIread(void) {
+ uint8_t reply = 0;
+ for (uint8_t i=0; i<8; i++) {
+ digitalWrite(_sclk, LOW);
+
+ digitalWrite(_sclk, HIGH);
if (digitalRead(_miso))
- //if ((*misoportreg) & misopin)
reply |= _BV(i);
- delayMicroseconds(5);
}
- digitalWrite(_cs, HIGH);
-
- return reply;
+ return reply;
}
+inline uint8_t Adafruit_GP9002::fastSPIread(void) {
+ uint8_t reply = 0;
+ for (uint8_t i=0; i<8; i++) {
+ *clkport &= ~clkpinmask;
+
+ *clkport |= clkpinmask;
+ if ((*misopin) & misopinmask)
+ reply |= _BV(i);
+ }
+ return reply;
+}
void Adafruit_GP9002::command(uint8_t d) {
- volatile uint8_t *sclkportreg, *mosiportreg;
- uint8_t sclkpin, mosipin;
+ *dcport |= dcpinmask;
+ *csport &= ~cspinmask;
+ fastSPIwrite(d);
+ *csport |= cspinmask;
+ delayMicroseconds(1); // should be 400ns actually
+}
- digitalWrite(_dc, HIGH);
- digitalWrite(_cs, LOW);
+inline void Adafruit_GP9002::dataWrite(uint8_t d) {
+ *dcport &= ~dcpinmask;
+ *csport &= ~cspinmask;
- /*
- sclkportreg = portOutputRegister(digitalPinToPort(_sclk));
- sclkpin = digitalPinToBitMask(_sclk);
-
- mosiportreg = portOutputRegister(digitalPinToPort(_mosi));
- mosipin = digitalPinToBitMask(_mosi);
- */
- for (uint8_t i=0; i<8; i++) {
+ fastSPIwrite(d);
- digitalWrite(_sclk, LOW);
- //*sclkportreg &= ~sclkpin;
- if (d & _BV(i)) {
- digitalWrite(_mosi, HIGH);
- //*mosiportreg |= mosipin;
- } else {
- digitalWrite(_mosi, LOW);
- //*mosiportreg &= ~mosipin;
- }
- digitalWrite(_sclk, HIGH);
- //*sclkportreg |= sclkpin;
- }
- digitalWrite(_cs, HIGH);
+ *csport |= cspinmask;
+ delayMicroseconds(1); // should be 600ns actually
}
+inline uint8_t Adafruit_GP9002::dataRead() {
+ uint8_t r;
+
+ *dcport &= ~dcpinmask;
+ *csport &= ~cspinmask;
-uint8_t Adafruit_GP9002::data(uint8_t d) {
- return spiTransfer(d, LOW);
+ r = fastSPIread();
+
+ *csport |= cspinmask;
+ delayMicroseconds(1);
+
+ return r;
}
void Adafruit_GP9002::setBrightness(uint8_t val) {
@@ -224,6 +243,8 @@ void Adafruit_GP9002::setBrightness(uint8_t val) {
// clear everything
void Adafruit_GP9002::clearDisplay(void) {
command(GP9002_CLEARSCREEN);
+
+ delay(1);
}
void Adafruit_GP9002::displayOff(void) {
View
26 Adafruit_GP9002.h
@@ -7,7 +7,7 @@
#include "WProgram.h"
#endif
-#include "Adafruit_MonoGfx.h"
+#include "Adafruit_GFX.h"
#define BLACK 0
#define WHITE 1
@@ -24,7 +24,7 @@
#define GP9002_LOWERADDR1 0x0A
#define GP9002_HIGHERADDR1 0x0B
#define GP9002_LOWERADDR2 0x0C
-#define GP9002_HIGHERADDR1 0x1D
+#define GP9002_HIGHERADDR2 0x0D
#define GP9002_ADDRL 0x0E
#define GP9002_ADDRH 0x0F
#define GP9002_OR 0x10
@@ -41,31 +41,37 @@
#define GP9002_CHARBRIGHT 0x24
-class Adafruit_GP9002 : public Adafruit_MonoGfx {
+class Adafruit_GP9002 : public Adafruit_GFX {
public:
Adafruit_GP9002(int8_t SCLK, int8_t MISO, int8_t MOSI,
int8_t CS, int8_t DC);
// particular to this display
void begin(void);
- uint8_t spiTransfer(uint8_t d, uint8_t datacommand);
+ uint8_t slowSPIread();
+ uint8_t fastSPIread();
+ void slowSPIwrite(uint8_t);
+ void fastSPIwrite(uint8_t);
+
void command(uint8_t c);
- uint8_t data(uint8_t c);
+ void dataWrite(uint8_t c);
+ uint8_t dataRead(void);
void setBrightness(uint8_t val);
void invert(uint8_t i);
void displayOn();
void displayOff();
void clearDisplay(void);
- void drawPixel(uint8_t x, uint8_t y, uint8_t color);
- void drawFastVLine(uint8_t x, uint8_t y, uint8_t h, uint8_t color);
-
- void drawChar(uint8_t x, uint8_t line, uint8_t c);
- void drawString(uint8_t x, uint8_t line, char *c);
+ void drawPixel(uint16_t x, uint16_t y, uint16_t color);
+ void drawFastVLine(uint16_t x, uint16_t y, uint16_t h, uint16_t color);
private:
int8_t _miso, _mosi, _sclk, _dc, _cs;
+
+ volatile uint8_t *mosiport, *misopin, *clkport, *csport, *dcport;
+ uint8_t mosipinmask, misopinmask, clkpinmask, cspinmask, dcpinmask;
+
void spiwrite(uint8_t c);
};
View
148 Adafruit_MonoGfx.cpp
@@ -1,148 +0,0 @@
-#include "Adafruit_MonoGfx.h"
-
-// draw a circle outline
-void Adafruit_MonoGfx::drawCircle(uint8_t x0, uint8_t y0, uint8_t r,
- uint8_t color) {
- int8_t f = 1 - r;
- int8_t ddF_x = 1;
- int8_t ddF_y = -2 * r;
- int8_t x = 0;
- int8_t y = r;
-
- drawPixel(x0, y0+r, color);
- drawPixel(x0, y0-r, color);
- drawPixel(x0+r, y0, color);
- drawPixel(x0-r, y0, color);
-
- while (x<y) {
- if (f >= 0) {
- y--;
- ddF_y += 2;
- f += ddF_y;
- }
- x++;
- ddF_x += 2;
- f += ddF_x;
-
- drawPixel(x0 + x, y0 + y, color);
- drawPixel(x0 - x, y0 + y, color);
- drawPixel(x0 + x, y0 - y, color);
- drawPixel(x0 - x, y0 - y, color);
-
- drawPixel(x0 + y, y0 + x, color);
- drawPixel(x0 - y, y0 + x, color);
- drawPixel(x0 + y, y0 - x, color);
- drawPixel(x0 - y, y0 - x, color);
-
- }
-}
-
-void Adafruit_MonoGfx::fillCircle(uint8_t x0, uint8_t y0, uint8_t r,
- uint8_t color) {
- int8_t f = 1 - r;
- int8_t ddF_x = 1;
- int8_t ddF_y = -2 * r;
- int8_t x = 0;
- int8_t y = r;
-
- drawFastVLine(x0, y0-r, r*2+1, color);
-
- while (x<y) {
- if (f >= 0) {
- y--;
- ddF_y += 2;
- f += ddF_y;
- }
- x++;
- ddF_x += 2;
- f += ddF_x;
-
- drawFastVLine(x0+x, y0-y, y*2+1, color);
- drawFastVLine(x0-x, y0-y, y*2+1, color);
-
- drawFastVLine(x0+y, y0-x, x*2+1, color);
- drawFastVLine(x0-y, y0-x, x*2+1, color);
- }
-}
-
-// bresenham's algorithm - thx wikpedia
-void Adafruit_MonoGfx::drawLine(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1,
- uint8_t color) {
- uint8_t steep = abs(y1 - y0) > abs(x1 - x0);
- if (steep) {
- swap(x0, y0);
- swap(x1, y1);
- }
-
- if (x0 > x1) {
- swap(x0, x1);
- swap(y0, y1);
- }
-
- uint8_t dx, dy;
- dx = x1 - x0;
- dy = abs(y1 - y0);
-
- int8_t err = dx / 2;
- int8_t ystep;
-
- if (y0 < y1) {
- ystep = 1;
- } else {
- ystep = -1;}
-
- for (; x0<x1; x0++) {
- if (steep) {
- drawPixel(y0, x0, color);
- } else {
- drawPixel(x0, y0, color);
- }
- err -= dy;
- if (err < 0) {
- y0 += ystep;
- err += dx;
- }
- }
-}
-
-
-// draw a rectangle
-void Adafruit_MonoGfx::drawRect(uint8_t x, uint8_t y, uint8_t w, uint8_t h,
- uint8_t color) {
- // very stupid version, but works!
- for (uint8_t i=x; i<x+w; i++) {
- drawPixel(i, y, color);
- drawPixel(i, y+h-1, color);
- }
- for (uint8_t i=y; i<y+h; i++) {
- drawPixel(x, i, color);
- drawPixel(x+w-1, i, color);
- }
-}
-
-void Adafruit_MonoGfx::drawFastVLine(uint8_t x, uint8_t y, uint8_t h, uint8_t color) {
- // stupidest version
- for (uint8_t j=y; j<y+h; j++) {
- drawPixel(x, j, color);
- }
-}
-
-void Adafruit_MonoGfx::fillRect(uint8_t x, uint8_t y, uint8_t w, uint8_t h,
- uint8_t color) {
- // stupidest version
- for (uint8_t i=x; i<x+w; i++) {
- drawFastVLine(i, y, h, color);
- }
-}
-
-void Adafruit_MonoGfx::drawBitmap(uint8_t x, uint8_t y,
- const uint8_t *bitmap, uint8_t w, uint8_t h,
- uint8_t color) {
- for (uint8_t j=0; j<h; j++) {
- for (uint8_t i=0; i<w; i++ ) {
- if (pgm_read_byte(bitmap + i + (j/8)*w) & _BV(j%8)) {
- drawPixel(x+i, y+j, color);
- }
- }
- }
-}
View
46 Adafruit_MonoGfx.h
@@ -1,46 +0,0 @@
-#ifndef _ADAFRUIT_MONOGFX_H
-#define _ADAFRUIT_MONOGFX_H
-
-#if ARDUINO >= 100
- #include "Arduino.h"
-#else
- #include "WProgram.h"
-#endif
-
-#define swap(a, b) { uint8_t t = a; a = b; b = t; }
-
-class Adafruit_MonoGfx {
- public:
- // this must be defined by the subclass
- virtual void drawPixel(uint8_t x, uint8_t y, uint8_t color);
-
- // these are 'generic' drawing functions, so we can share them!
- void drawLine(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1,
- uint8_t color);
- virtual void drawFastVLine(uint8_t x, uint8_t y, uint8_t h, uint8_t color);
- void drawRect(uint8_t x, uint8_t y, uint8_t w, uint8_t h,
- uint8_t color);
- void fillRect(uint8_t x, uint8_t y, uint8_t w, uint8_t h,
- uint8_t color);
-
- void drawCircle(uint8_t x0, uint8_t y0, uint8_t r,
- uint8_t color);
- void fillCircle(uint8_t x0, uint8_t y0, uint8_t r,
- uint8_t color);
-
- void drawBitmap(uint8_t x, uint8_t y,
- const uint8_t *bitmap, uint8_t w, uint8_t h,
- uint8_t color);
-
-
- // return the size of the display
- uint8_t width() { return WIDTH; }
- uint8_t height() { return HEIGHT; }
-
- protected:
- uint8_t WIDTH, HEIGHT;
-
-
-};
-
-#endif
View
265 examples/GraphicVFDtest/GraphicVFDtest.pde
@@ -0,0 +1,265 @@
+#include "Adafruit_GFX.h"
+#include "Adafruit_GP9002.h"
+
+#define _MISO 2 // #8
+#define _CLK 3 // #11
+#define _MOSI 4 // #12
+#define _DC 6 // #14
+#define _CS 5 // #13
+
+
+Adafruit_GP9002 display = Adafruit_GP9002(_CLK, _MISO, _MOSI, _CS, _DC);
+
+// connect #15, #16, #17 to 5V
+// connect #9 #18 #19 #20 to ground
+
+#define NUMFLAKES 10
+#define XPOS 0
+#define YPOS 1
+#define DELTAY 2
+
+
+#define LOGO16_GLCD_HEIGHT 16
+#define LOGO16_GLCD_WIDTH 16
+static unsigned char __attribute__ ((progmem)) logo16_glcd_bmp[]={
+0x30, 0xf0, 0xf0, 0xf0, 0xf0, 0x30, 0xf8, 0xbe, 0x9f, 0xff, 0xf8, 0xc0, 0xc0, 0xc0, 0x80, 0x00,
+0x20, 0x3c, 0x3f, 0x3f, 0x1f, 0x19, 0x1f, 0x7b, 0xfb, 0xfe, 0xfe, 0x07, 0x07, 0x07, 0x03, 0x00, };
+
+
+void setup() {
+ Serial.begin(9600);
+
+ display.begin();
+ // init done
+
+ delay(2000);
+ display.clearDisplay(); // clears the screen and buffer
+
+ // draw a single pixel
+ display.drawPixel(10, 10, WHITE);
+ delay(2000);
+ display.clearDisplay();
+
+ // draw many lines
+ testdrawline();
+ delay(2000);
+ display.clearDisplay();
+
+ // draw rectangles
+ testdrawrect();
+ delay(2000);
+ display.clearDisplay();
+
+ // draw multiple rectangles
+ testfillrect();
+ delay(2000);
+ display.clearDisplay();
+
+ // draw mulitple circles
+ testdrawcircle();
+ delay(2000);
+ display.clearDisplay();
+
+ // draw a circle, 10 pixel radius
+ display.fillCircle(display.width()/2, display.height()/2, 10, WHITE);
+ delay(2000);
+ display.clearDisplay();
+
+ testdrawroundrect();
+ delay(2000);
+ display.clearDisplay();
+
+ testfillroundrect();
+ delay(2000);
+ display.clearDisplay();
+
+ testdrawtriangle();
+ delay(2000);
+ display.clearDisplay();
+
+ testfilltriangle();
+ delay(2000);
+ display.clearDisplay();
+
+ // draw the first ~12 characters in the font
+ testdrawchar();
+ delay(2000);
+ display.clearDisplay();
+
+ // text display tests
+ display.setTextSize(1);
+ display.setTextColor(WHITE);
+ display.setCursor(0,0);
+ display.println("Hello, world!");
+ display.setTextColor(BLACK, WHITE); // 'inverted' text
+ display.println(3.141592);
+ display.setTextSize(2);
+ display.setTextColor(WHITE);
+ display.print("0x"); display.println(0xDEADBEEF, HEX);
+ delay(2000);
+
+ // miniature bitmap display
+ display.clearDisplay();
+ display.drawBitmap(30, 16, logo16_glcd_bmp, 16, 16, 1);
+
+ // invert the display
+ display.invertDisplay(true);
+ delay(1000);
+ display.invertDisplay(false);
+ delay(1000);
+
+ // draw a bitmap icon and 'animate' movement
+ testdrawbitmap(logo16_glcd_bmp, LOGO16_GLCD_HEIGHT, LOGO16_GLCD_WIDTH);
+}
+
+
+void loop() {
+
+}
+
+
+void testdrawbitmap(const uint8_t *bitmap, uint8_t w, uint8_t h) {
+ uint8_t icons[NUMFLAKES][3];
+ srandom(666); // whatever seed
+
+ // initialize
+ for (uint8_t f=0; f< NUMFLAKES; f++) {
+ icons[f][XPOS] = random() % display.width();
+ icons[f][YPOS] = 0;
+ icons[f][DELTAY] = random() % 5 + 1;
+
+ Serial.print("x: ");
+ Serial.print(icons[f][XPOS], DEC);
+ Serial.print(" y: ");
+ Serial.print(icons[f][YPOS], DEC);
+ Serial.print(" dy: ");
+ Serial.println(icons[f][DELTAY], DEC);
+ }
+
+ while (1) {
+ // draw each icon
+ for (uint8_t f=0; f< NUMFLAKES; f++) {
+ display.drawBitmap(icons[f][XPOS], icons[f][YPOS], logo16_glcd_bmp, w, h, WHITE);
+ }
+ delay(200);
+
+ // then erase it + move it
+ for (uint8_t f=0; f< NUMFLAKES; f++) {
+ display.drawBitmap(icons[f][XPOS], icons[f][YPOS], logo16_glcd_bmp, w, h, BLACK);
+ // move it
+ icons[f][YPOS] += icons[f][DELTAY];
+ // if its gone, reinit
+ if (icons[f][YPOS] > display.height()) {
+ icons[f][XPOS] = random() % display.width();
+ icons[f][YPOS] = 0;
+ icons[f][DELTAY] = random() % 5 + 1;
+ }
+ }
+ }
+}
+
+
+void testdrawchar(void) {
+ display.setTextSize(1);
+ display.setTextColor(WHITE);
+ display.setCursor(0,0);
+
+ for (uint8_t i=0; i < 168; i++) {
+ if (i == '\n') continue;
+ display.write(i);
+ //if ((i > 0) && (i % 14 == 0))
+ //display.println();
+ }
+}
+
+void testdrawcircle(void) {
+ for (uint8_t i=0; i<display.height(); i+=2) {
+ display.drawCircle(display.width()/2, display.height()/2, i, WHITE);
+ }
+}
+
+void testfillrect(void) {
+ uint8_t color = 1;
+ for (uint8_t i=0; i<display.height()/2; i+=3) {
+ // alternate colors
+ display.fillRect(i, i, display.width()-i*2, display.height()-i*2, color%2);
+ color++;
+ }
+}
+
+void testdrawtriangle(void) {
+ for (uint16_t i=0; i<min(display.width(),display.height())/2; i+=5) {
+ display.drawTriangle(display.width()/2, display.height()/2-i,
+ display.width()/2-i, display.height()/2+i,
+ display.width()/2+i, display.height()/2+i, WHITE);
+ }
+}
+
+void testfilltriangle(void) {
+ uint8_t color = WHITE;
+ for (int16_t i=min(display.width(),display.height())/2; i>0; i-=5) {
+ display.fillTriangle(display.width()/2, display.height()/2-i,
+ display.width()/2-i, display.height()/2+i,
+ display.width()/2+i, display.height()/2+i, color);
+ if (color == BLACK) color = WHITE;
+ else color = BLACK;
+ }
+}
+
+void testdrawroundrect(void) {
+ for (uint8_t i=0; i<display.height()/2-2; i+=2) {
+ display.drawRoundRect(i, i, display.width()-2*i, display.height()-2*i, display.height()/4, WHITE);
+ }
+}
+
+void testfillroundrect(void) {
+ uint8_t color = WHITE;
+ for (uint8_t i=0; i<display.height()/2-2; i+=2) {
+ display.fillRoundRect(i, i, display.width()-2*i, display.height()-2*i, display.height()/4, color);
+ if (color == BLACK) color = WHITE;
+ else color = BLACK;
+ }
+}
+
+void testdrawrect(void) {
+ for (uint8_t i=0; i<display.height()/2; i+=2) {
+ display.drawRect(i, i, display.width()-2*i, display.height()-2*i, WHITE);
+ }
+}
+
+void testdrawline() {
+ for (uint8_t i=0; i<display.width(); i+=4) {
+ display.drawLine(0, 0, i, display.height()-1, WHITE);
+ }
+ for (uint8_t i=0; i<display.height(); i+=4) {
+ display.drawLine(0, 0, display.width()-1, i, WHITE);
+ }
+ delay(250);
+
+ display.clearDisplay();
+ for (uint8_t i=0; i<display.width(); i+=4) {
+ display.drawLine(0, display.height()-1, i, 0, WHITE);
+ }
+ for (int8_t i=display.height()-1; i>=0; i-=4) {
+ display.drawLine(0, display.height()-1, display.width()-1, i, WHITE);
+ }
+ delay(250);
+
+ display.clearDisplay();
+ for (int8_t i=display.width()-1; i>=0; i-=4) {
+ display.drawLine(display.width()-1, display.height()-1, i, 0, WHITE);
+ }
+ for (int8_t i=display.height()-1; i>=0; i-=4) {
+ display.drawLine(display.width()-1, display.height()-1, 0, i, WHITE);
+ }
+ delay(250);
+
+ display.clearDisplay();
+ for (uint8_t i=0; i<display.height(); i+=4) {
+ display.drawLine(display.width()-1, 0, 0, i, WHITE);
+ }
+ for (uint8_t i=0; i<display.width(); i+=4) {
+ display.drawLine(display.width()-1, 0, i, display.height()-1, WHITE);
+ }
+ delay(250);
+}
View
266 glcdfont.c
@@ -1,266 +0,0 @@
-#include <avr/io.h>
-#include <avr/pgmspace.h>
-
-#ifndef FONT5X7_H
-#define FONT5X7_H
-
-// standard ascii 5x7 font
-
-static unsigned char font[] PROGMEM = {
- 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x3E, 0x5B, 0x4F, 0x5B, 0x3E,
- 0x3E, 0x6B, 0x4F, 0x6B, 0x3E,
- 0x1C, 0x3E, 0x7C, 0x3E, 0x1C,
- 0x18, 0x3C, 0x7E, 0x3C, 0x18,
- 0x1C, 0x57, 0x7D, 0x57, 0x1C,
- 0x1C, 0x5E, 0x7F, 0x5E, 0x1C,
- 0x00, 0x18, 0x3C, 0x18, 0x00,
- 0xFF, 0xE7, 0xC3, 0xE7, 0xFF,
- 0x00, 0x18, 0x24, 0x18, 0x00,
- 0xFF, 0xE7, 0xDB, 0xE7, 0xFF,
- 0x30, 0x48, 0x3A, 0x06, 0x0E,
- 0x26, 0x29, 0x79, 0x29, 0x26,
- 0x40, 0x7F, 0x05, 0x05, 0x07,
- 0x40, 0x7F, 0x05, 0x25, 0x3F,
- 0x5A, 0x3C, 0xE7, 0x3C, 0x5A,
- 0x7F, 0x3E, 0x1C, 0x1C, 0x08,
- 0x08, 0x1C, 0x1C, 0x3E, 0x7F,
- 0x14, 0x22, 0x7F, 0x22, 0x14,
- 0x5F, 0x5F, 0x00, 0x5F, 0x5F,
- 0x06, 0x09, 0x7F, 0x01, 0x7F,
- 0x00, 0x66, 0x89, 0x95, 0x6A,
- 0x60, 0x60, 0x60, 0x60, 0x60,
- 0x94, 0xA2, 0xFF, 0xA2, 0x94,
- 0x08, 0x04, 0x7E, 0x04, 0x08,
- 0x10, 0x20, 0x7E, 0x20, 0x10,
- 0x08, 0x08, 0x2A, 0x1C, 0x08,
- 0x08, 0x1C, 0x2A, 0x08, 0x08,
- 0x1E, 0x10, 0x10, 0x10, 0x10,
- 0x0C, 0x1E, 0x0C, 0x1E, 0x0C,
- 0x30, 0x38, 0x3E, 0x38, 0x30,
- 0x06, 0x0E, 0x3E, 0x0E, 0x06,
- 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x5F, 0x00, 0x00,
- 0x00, 0x07, 0x00, 0x07, 0x00,
- 0x14, 0x7F, 0x14, 0x7F, 0x14,
- 0x24, 0x2A, 0x7F, 0x2A, 0x12,
- 0x23, 0x13, 0x08, 0x64, 0x62,
- 0x36, 0x49, 0x56, 0x20, 0x50,
- 0x00, 0x08, 0x07, 0x03, 0x00,
- 0x00, 0x1C, 0x22, 0x41, 0x00,
- 0x00, 0x41, 0x22, 0x1C, 0x00,
- 0x2A, 0x1C, 0x7F, 0x1C, 0x2A,
- 0x08, 0x08, 0x3E, 0x08, 0x08,
- 0x00, 0x80, 0x70, 0x30, 0x00,
- 0x08, 0x08, 0x08, 0x08, 0x08,
- 0x00, 0x00, 0x60, 0x60, 0x00,
- 0x20, 0x10, 0x08, 0x04, 0x02,
- 0x3E, 0x51, 0x49, 0x45, 0x3E,
- 0x00, 0x42, 0x7F, 0x40, 0x00,
- 0x72, 0x49, 0x49, 0x49, 0x46,
- 0x21, 0x41, 0x49, 0x4D, 0x33,
- 0x18, 0x14, 0x12, 0x7F, 0x10,
- 0x27, 0x45, 0x45, 0x45, 0x39,
- 0x3C, 0x4A, 0x49, 0x49, 0x31,
- 0x41, 0x21, 0x11, 0x09, 0x07,
- 0x36, 0x49, 0x49, 0x49, 0x36,
- 0x46, 0x49, 0x49, 0x29, 0x1E,
- 0x00, 0x00, 0x14, 0x00, 0x00,
- 0x00, 0x40, 0x34, 0x00, 0x00,
- 0x00, 0x08, 0x14, 0x22, 0x41,
- 0x14, 0x14, 0x14, 0x14, 0x14,
- 0x00, 0x41, 0x22, 0x14, 0x08,
- 0x02, 0x01, 0x59, 0x09, 0x06,
- 0x3E, 0x41, 0x5D, 0x59, 0x4E,
- 0x7C, 0x12, 0x11, 0x12, 0x7C,
- 0x7F, 0x49, 0x49, 0x49, 0x36,
- 0x3E, 0x41, 0x41, 0x41, 0x22,
- 0x7F, 0x41, 0x41, 0x41, 0x3E,
- 0x7F, 0x49, 0x49, 0x49, 0x41,
- 0x7F, 0x09, 0x09, 0x09, 0x01,
- 0x3E, 0x41, 0x41, 0x51, 0x73,
- 0x7F, 0x08, 0x08, 0x08, 0x7F,
- 0x00, 0x41, 0x7F, 0x41, 0x00,
- 0x20, 0x40, 0x41, 0x3F, 0x01,
- 0x7F, 0x08, 0x14, 0x22, 0x41,
- 0x7F, 0x40, 0x40, 0x40, 0x40,
- 0x7F, 0x02, 0x1C, 0x02, 0x7F,
- 0x7F, 0x04, 0x08, 0x10, 0x7F,
- 0x3E, 0x41, 0x41, 0x41, 0x3E,
- 0x7F, 0x09, 0x09, 0x09, 0x06,
- 0x3E, 0x41, 0x51, 0x21, 0x5E,
- 0x7F, 0x09, 0x19, 0x29, 0x46,
- 0x26, 0x49, 0x49, 0x49, 0x32,
- 0x03, 0x01, 0x7F, 0x01, 0x03,
- 0x3F, 0x40, 0x40, 0x40, 0x3F,
- 0x1F, 0x20, 0x40, 0x20, 0x1F,
- 0x3F, 0x40, 0x38, 0x40, 0x3F,
- 0x63, 0x14, 0x08, 0x14, 0x63,
- 0x03, 0x04, 0x78, 0x04, 0x03,
- 0x61, 0x59, 0x49, 0x4D, 0x43,
- 0x00, 0x7F, 0x41, 0x41, 0x41,
- 0x02, 0x04, 0x08, 0x10, 0x20,
- 0x00, 0x41, 0x41, 0x41, 0x7F,
- 0x04, 0x02, 0x01, 0x02, 0x04,
- 0x40, 0x40, 0x40, 0x40, 0x40,
- 0x00, 0x03, 0x07, 0x08, 0x00,
- 0x20, 0x54, 0x54, 0x78, 0x40,
- 0x7F, 0x28, 0x44, 0x44, 0x38,
- 0x38, 0x44, 0x44, 0x44, 0x28,
- 0x38, 0x44, 0x44, 0x28, 0x7F,
- 0x38, 0x54, 0x54, 0x54, 0x18,
- 0x00, 0x08, 0x7E, 0x09, 0x02,
- 0x18, 0xA4, 0xA4, 0x9C, 0x78,
- 0x7F, 0x08, 0x04, 0x04, 0x78,
- 0x00, 0x44, 0x7D, 0x40, 0x00,
- 0x20, 0x40, 0x40, 0x3D, 0x00,
- 0x7F, 0x10, 0x28, 0x44, 0x00,
- 0x00, 0x41, 0x7F, 0x40, 0x00,
- 0x7C, 0x04, 0x78, 0x04, 0x78,
- 0x7C, 0x08, 0x04, 0x04, 0x78,
- 0x38, 0x44, 0x44, 0x44, 0x38,
- 0xFC, 0x18, 0x24, 0x24, 0x18,
- 0x18, 0x24, 0x24, 0x18, 0xFC,
- 0x7C, 0x08, 0x04, 0x04, 0x08,
- 0x48, 0x54, 0x54, 0x54, 0x24,
- 0x04, 0x04, 0x3F, 0x44, 0x24,
- 0x3C, 0x40, 0x40, 0x20, 0x7C,
- 0x1C, 0x20, 0x40, 0x20, 0x1C,
- 0x3C, 0x40, 0x30, 0x40, 0x3C,
- 0x44, 0x28, 0x10, 0x28, 0x44,
- 0x4C, 0x90, 0x90, 0x90, 0x7C,
- 0x44, 0x64, 0x54, 0x4C, 0x44,
- 0x00, 0x08, 0x36, 0x41, 0x00,
- 0x00, 0x00, 0x77, 0x00, 0x00,
- 0x00, 0x41, 0x36, 0x08, 0x00,
- 0x02, 0x01, 0x02, 0x04, 0x02,
- 0x3C, 0x26, 0x23, 0x26, 0x3C,
- 0x1E, 0xA1, 0xA1, 0x61, 0x12,
- 0x3A, 0x40, 0x40, 0x20, 0x7A,
- 0x38, 0x54, 0x54, 0x55, 0x59,
- 0x21, 0x55, 0x55, 0x79, 0x41,
- 0x21, 0x54, 0x54, 0x78, 0x41,
- 0x21, 0x55, 0x54, 0x78, 0x40,
- 0x20, 0x54, 0x55, 0x79, 0x40,
- 0x0C, 0x1E, 0x52, 0x72, 0x12,
- 0x39, 0x55, 0x55, 0x55, 0x59,
- 0x39, 0x54, 0x54, 0x54, 0x59,
- 0x39, 0x55, 0x54, 0x54, 0x58,
- 0x00, 0x00, 0x45, 0x7C, 0x41,
- 0x00, 0x02, 0x45, 0x7D, 0x42,
- 0x00, 0x01, 0x45, 0x7C, 0x40,
- 0xF0, 0x29, 0x24, 0x29, 0xF0,
- 0xF0, 0x28, 0x25, 0x28, 0xF0,
- 0x7C, 0x54, 0x55, 0x45, 0x00,
- 0x20, 0x54, 0x54, 0x7C, 0x54,
- 0x7C, 0x0A, 0x09, 0x7F, 0x49,
- 0x32, 0x49, 0x49, 0x49, 0x32,
- 0x32, 0x48, 0x48, 0x48, 0x32,
- 0x32, 0x4A, 0x48, 0x48, 0x30,
- 0x3A, 0x41, 0x41, 0x21, 0x7A,
- 0x3A, 0x42, 0x40, 0x20, 0x78,
- 0x00, 0x9D, 0xA0, 0xA0, 0x7D,
- 0x39, 0x44, 0x44, 0x44, 0x39,
- 0x3D, 0x40, 0x40, 0x40, 0x3D,
- 0x3C, 0x24, 0xFF, 0x24, 0x24,
- 0x48, 0x7E, 0x49, 0x43, 0x66,
- 0x2B, 0x2F, 0xFC, 0x2F, 0x2B,
- 0xFF, 0x09, 0x29, 0xF6, 0x20,
- 0xC0, 0x88, 0x7E, 0x09, 0x03,
- 0x20, 0x54, 0x54, 0x79, 0x41,
- 0x00, 0x00, 0x44, 0x7D, 0x41,
- 0x30, 0x48, 0x48, 0x4A, 0x32,
- 0x38, 0x40, 0x40, 0x22, 0x7A,
- 0x00, 0x7A, 0x0A, 0x0A, 0x72,
- 0x7D, 0x0D, 0x19, 0x31, 0x7D,
- 0x26, 0x29, 0x29, 0x2F, 0x28,
- 0x26, 0x29, 0x29, 0x29, 0x26,
- 0x30, 0x48, 0x4D, 0x40, 0x20,
- 0x38, 0x08, 0x08, 0x08, 0x08,
- 0x08, 0x08, 0x08, 0x08, 0x38,
- 0x2F, 0x10, 0xC8, 0xAC, 0xBA,
- 0x2F, 0x10, 0x28, 0x34, 0xFA,
- 0x00, 0x00, 0x7B, 0x00, 0x00,
- 0x08, 0x14, 0x2A, 0x14, 0x22,
- 0x22, 0x14, 0x2A, 0x14, 0x08,
- 0xAA, 0x00, 0x55, 0x00, 0xAA,
- 0xAA, 0x55, 0xAA, 0x55, 0xAA,
- 0x00, 0x00, 0x00, 0xFF, 0x00,
- 0x10, 0x10, 0x10, 0xFF, 0x00,
- 0x14, 0x14, 0x14, 0xFF, 0x00,
- 0x10, 0x10, 0xFF, 0x00, 0xFF,
- 0x10, 0x10, 0xF0, 0x10, 0xF0,
- 0x14, 0x14, 0x14, 0xFC, 0x00,
- 0x14, 0x14, 0xF7, 0x00, 0xFF,
- 0x00, 0x00, 0xFF, 0x00, 0xFF,
- 0x14, 0x14, 0xF4, 0x04, 0xFC,
- 0x14, 0x14, 0x17, 0x10, 0x1F,
- 0x10, 0x10, 0x1F, 0x10, 0x1F,
- 0x14, 0x14, 0x14, 0x1F, 0x00,
- 0x10, 0x10, 0x10, 0xF0, 0x00,
- 0x00, 0x00, 0x00, 0x1F, 0x10,
- 0x10, 0x10, 0x10, 0x1F, 0x10,
- 0x10, 0x10, 0x10, 0xF0, 0x10,
- 0x00, 0x00, 0x00, 0xFF, 0x10,
- 0x10, 0x10, 0x10, 0x10, 0x10,
- 0x10, 0x10, 0x10, 0xFF, 0x10,
- 0x00, 0x00, 0x00, 0xFF, 0x14,
- 0x00, 0x00, 0xFF, 0x00, 0xFF,
- 0x00, 0x00, 0x1F, 0x10, 0x17,
- 0x00, 0x00, 0xFC, 0x04, 0xF4,
- 0x14, 0x14, 0x17, 0x10, 0x17,
- 0x14, 0x14, 0xF4, 0x04, 0xF4,
- 0x00, 0x00, 0xFF, 0x00, 0xF7,
- 0x14, 0x14, 0x14, 0x14, 0x14,
- 0x14, 0x14, 0xF7, 0x00, 0xF7,
- 0x14, 0x14, 0x14, 0x17, 0x14,
- 0x10, 0x10, 0x1F, 0x10, 0x1F,
- 0x14, 0x14, 0x14, 0xF4, 0x14,
- 0x10, 0x10, 0xF0, 0x10, 0xF0,
- 0x00, 0x00, 0x1F, 0x10, 0x1F,
- 0x00, 0x00, 0x00, 0x1F, 0x14,
- 0x00, 0x00, 0x00, 0xFC, 0x14,
- 0x00, 0x00, 0xF0, 0x10, 0xF0,
- 0x10, 0x10, 0xFF, 0x10, 0xFF,
- 0x14, 0x14, 0x14, 0xFF, 0x14,
- 0x10, 0x10, 0x10, 0x1F, 0x00,
- 0x00, 0x00, 0x00, 0xF0, 0x10,
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
- 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
- 0xFF, 0xFF, 0xFF, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0xFF, 0xFF,
- 0x0F, 0x0F, 0x0F, 0x0F, 0x0F,
- 0x38, 0x44, 0x44, 0x38, 0x44,
- 0x7C, 0x2A, 0x2A, 0x3E, 0x14,
- 0x7E, 0x02, 0x02, 0x06, 0x06,
- 0x02, 0x7E, 0x02, 0x7E, 0x02,
- 0x63, 0x55, 0x49, 0x41, 0x63,
- 0x38, 0x44, 0x44, 0x3C, 0x04,
- 0x40, 0x7E, 0x20, 0x1E, 0x20,
- 0x06, 0x02, 0x7E, 0x02, 0x02,
- 0x99, 0xA5, 0xE7, 0xA5, 0x99,
- 0x1C, 0x2A, 0x49, 0x2A, 0x1C,
- 0x4C, 0x72, 0x01, 0x72, 0x4C,
- 0x30, 0x4A, 0x4D, 0x4D, 0x30,
- 0x30, 0x48, 0x78, 0x48, 0x30,
- 0xBC, 0x62, 0x5A, 0x46, 0x3D,
- 0x3E, 0x49, 0x49, 0x49, 0x00,
- 0x7E, 0x01, 0x01, 0x01, 0x7E,
- 0x2A, 0x2A, 0x2A, 0x2A, 0x2A,
- 0x44, 0x44, 0x5F, 0x44, 0x44,
- 0x40, 0x51, 0x4A, 0x44, 0x40,
- 0x40, 0x44, 0x4A, 0x51, 0x40,
- 0x00, 0x00, 0xFF, 0x01, 0x03,
- 0xE0, 0x80, 0xFF, 0x00, 0x00,
- 0x08, 0x08, 0x6B, 0x6B, 0x08,
- 0x36, 0x12, 0x36, 0x24, 0x36,
- 0x06, 0x0F, 0x09, 0x0F, 0x06,
- 0x00, 0x00, 0x18, 0x18, 0x00,
- 0x00, 0x00, 0x10, 0x10, 0x00,
- 0x30, 0x40, 0xFF, 0x01, 0x01,
- 0x00, 0x1F, 0x01, 0x01, 0x1E,
- 0x00, 0x19, 0x1D, 0x17, 0x12,
- 0x00, 0x3C, 0x3C, 0x3C, 0x3C,
- 0x00, 0x00, 0x00, 0x00, 0x00,
-};
-#endif

0 comments on commit efc2862

Please sign in to comment.