Permalink
Browse files

Adafruit_GFX subclass + fixed 'ghosting' issue

  • Loading branch information...
1 parent 9dd9cd8 commit a875e9a38760b569b718ca02200db9ab4fc36014 @PaintYourDragon PaintYourDragon committed Apr 10, 2012
View
Oops, something went wrong.
View
@@ -4,8 +4,9 @@
#include "WProgram.h"
#include "pins_arduino.h"
#endif
+#include "Adafruit_GFX.h"
-class RGBmatrixPanel : public Print {
+class RGBmatrixPanel : public Adafruit_GFX {
public:
@@ -19,19 +20,12 @@ class RGBmatrixPanel : public Print {
void
begin(void),
- drawPixel(int x, int y, uint16_t c),
- drawLine(int x0, int y0, int x1, int y1, uint16_t c),
- drawRect(int x, int y, uint8_t w, uint8_t h, uint16_t c),
- fillRect(int x, int y, uint8_t w, uint8_t h, uint16_t c),
- drawCircle(int x0, int y0, uint8_t r, uint16_t c),
- fillCircle(int x0, int y0, uint8_t r, uint16_t c),
- fill(uint16_t c),
+ drawPixel(int16_t x, int16_t y, uint16_t c),
+ fillScreen(uint16_t c),
updateDisplay(void),
swapBuffers(boolean),
dumpMatrix(void);
uint8_t
- width(void),
- height(void),
*backBuffer(void);
uint16_t
Color333(uint8_t r, uint8_t g, uint8_t b),
@@ -41,25 +35,11 @@ class RGBmatrixPanel : public Print {
ColorHSV(long hue, uint8_t sat, uint8_t val, boolean gflag);
// Printing
- void
- attachInterrupt(void (*func)(void)),
- setCursor(int x, int y),
- setTextSize(uint8_t s),
- setTextColor(uint16_t c),
- drawChar(int x, int y, char c, uint16_t color, uint8_t size);
-#if ARDUINO >= 100
- size_t write(uint8_t c);
-#else
- void write(uint8_t c);
-#endif
-
private:
- uint8_t *matrixbuff[2];
- uint8_t nRows, nPlanes, textsize, backindex;
- int cursor_x, cursor_y;
- uint16_t textcolor;
- boolean swapflag;
+ uint8_t *matrixbuff[2];
+ uint8_t nRows, nPlanes, backindex;
+ boolean swapflag;
// Init/alloc code common to both constructors:
void init(uint8_t rows, uint8_t a, uint8_t b, uint8_t c,
@@ -1,7 +1,8 @@
// colorwheel demo for RGBmatrixPanel library.
// Renders a nice circle of hues on a 32x32 RGB LED matrix.
-#include "RGBmatrixPanel.h"
+#include <Adafruit_GFX.h> // Core graphics library
+#include <RGBmatrixPanel.h> // Hardware-specific library
#define A A3
#define B A2
@@ -3,7 +3,8 @@
// Uses precomputed image data stored in PROGMEM rather than
// calculating each pixel. Nearly instantaneous! Woo!
-#include "RGBmatrixPanel.h"
+#include <Adafruit_GFX.h> // Core graphics library
+#include <RGBmatrixPanel.h> // Hardware-specific library
#include "image.h"
#define A A3
@@ -1,15 +1,16 @@
// plasma demo for RGBmatrixPanel library.
// Demonstrates double-buffered animation on 16x32 RGB LED matrix.
-#include "RGBmatrixPanel.h"
-#include <avr/pgmspace.h>
+#include <avr/pgmspace.h>
+#include <Adafruit_GFX.h> // Core graphics library
+#include <RGBmatrixPanel.h> // Hardware-specific library
-#define A A0
-#define B A1
-#define C A2
#define CLK 8 // MUST be on PORTB!
#define LAT A3
#define OE 9
+#define A A0
+#define B A1
+#define C A2
// Last parameter = 'true' enables double-buffering, for flicker-free,
// buttery smooth animation. Note that NOTHING WILL SHOW ON THE DISPLAY
// until the first call to swapBuffers(). This is normal.
@@ -54,10 +55,10 @@ void setup() {
matrix.begin();
}
-const float radius1 = 16.3, radius2 = 23.0, radius3 = 40.8, radius4 = 44.2,
- centerx1 = 16.1, centerx2 = 11.6, centerx3 = 23.4, centerx4 = 4.1,
- centery1 = 8.7, centery2 = 6.5, centery3 = 14.0, centery4 = -2.9;
-float angle1 = 0.0, angle2 = 0.0, angle3 = 0.0, angle4 = 0.0;
+const float radius1 = 65.2, radius2 = 92.0, radius3 = 163.2, radius4 = 176.8,
+ centerx1 = 64.4, centerx2 = 46.4, centerx3 = 93.6, centerx4 = 16.4,
+ centery1 = 34.8, centery2 = 26.0, centery3 = 56.0, centery4 = -11.6;
+float angle1 = 0.0, angle2 = 0.0, angle3 = 0.0, angle4 = 0.0;
long hueShift = 0;
void loop() {
@@ -78,10 +79,10 @@ void loop() {
x1 = sx1; x2 = sx2; x3 = sx3; x4 = sx4;
for(x=0; x<matrix.width(); x++) {
value = hueShift
- + (int8_t)pgm_read_byte(sinetab + (uint8_t)((x1 * x1 + y1 * y1) >> 2))
- + (int8_t)pgm_read_byte(sinetab + (uint8_t)((x2 * x2 + y2 * y2) >> 2))
- + (int8_t)pgm_read_byte(sinetab + (uint8_t)((x3 * x3 + y3 * y3) >> 3))
- + (int8_t)pgm_read_byte(sinetab + (uint8_t)((x4 * x4 + y4 * y4) >> 3));
+ + (int8_t)pgm_read_byte(sinetab + (uint8_t)((x1 * x1 + y1 * y1) >> 4))
+ + (int8_t)pgm_read_byte(sinetab + (uint8_t)((x2 * x2 + y2 * y2) >> 4))
+ + (int8_t)pgm_read_byte(sinetab + (uint8_t)((x3 * x3 + y3 * y3) >> 5))
+ + (int8_t)pgm_read_byte(sinetab + (uint8_t)((x4 * x4 + y4 * y4) >> 5));
matrix.drawPixel(x, y, matrix.ColorHSV(value * 3, 255, 255, true));
x1--; x2--; x3--; x4--;
}
@@ -1,7 +1,8 @@
// plasma demo for RGBmatrixPanel library.
// Demonstrates unbuffered animation on 32x32 RGB LED matrix.
-#include "RGBmatrixPanel.h"
+#include <Adafruit_GFX.h> // Core graphics library
+#include <RGBmatrixPanel.h> // Hardware-specific library
#include <avr/pgmspace.h>
#define A A3
@@ -1,48 +1,51 @@
// scrolltext demo for RGBmatrixPanel library.
// Demonstrates double-buffered animation on 16x32 RGB LED matrix.
-#include "RGBmatrixPanel.h"
+#include <Adafruit_GFX.h> // Core graphics library
+#include <RGBmatrixPanel.h> // Hardware-specific library
-#define A A0
-#define B A1
-#define C A2
#define CLK 8 // MUST be on PORTB!
#define LAT A3
#define OE 9
+#define A A0
+#define B A1
+#define C A2
// Last parameter = 'true' enables double-buffering, for flicker-free,
// buttery smooth animation. Note that NOTHING WILL SHOW ON THE DISPLAY
// until the first call to swapBuffers(). This is normal.
RGBmatrixPanel matrix(A, B, C, CLK, LAT, OE, true);
-char str[] = "Adafruit 16x32 RGB LED Matrix";
-int textX = matrix.width(),
- textMin = sizeof(str) * -12;
-long hue = 0;
-int ball[3][4] = {
- 3, 0, 1, 1, // Initial X,Y pos & velocity for 3 bouncy balls
- 17, 15, 1, -1,
- 27, 4, -1, 1
+char str[] = "Adafruit 16x32 RGB LED Matrix";
+int textX = matrix.width(),
+ textMin = sizeof(str) * -12;
+long hue = 0;
+int8_t ball[3][4] = {
+ { 3, 0, 1, 1 }, // Initial X,Y pos & velocity for 3 bouncy balls
+ { 17, 15, 1, -1 },
+ { 27, 4, -1, 1 }
};
-uint16_t ballcolor[3] = {
- matrix.Color444(0,1,0),
- matrix.Color444(0,0,1),
- matrix.Color444(1,0,0)
+PROGMEM uint16_t ballcolor[3] = {
+ 0x0080, // Green=1
+ 0x0002, // Blue=1
+ 0x1000 // Red=1
};
void setup() {
matrix.begin();
+ matrix.setTextWrap(false); // Allow text to run off right edge
+ matrix.setTextSize(2);
}
void loop() {
byte i;
// Clear background
- matrix.fill(0);
+ matrix.fillScreen(0);
// Bounce three balls around
for(i=0; i<3; i++) {
// Draw 'ball'
- matrix.fillCircle(ball[i][0], ball[i][1], 5, ballcolor[i]);
+ matrix.fillCircle(ball[i][0], ball[i][1], 5, pgm_read_word(&ballcolor[i]));
// Update X, Y position
ball[i][0] += ball[i][2];
ball[i][1] += ball[i][3];
@@ -54,10 +57,10 @@ void loop() {
}
// Draw big scrolly text on top
- matrix.setTextSize(2);
- matrix.setCursor(textX, 1);
matrix.setTextColor(matrix.ColorHSV(hue, 255, 255, true));
+ matrix.setCursor(textX, 1);
matrix.print(str);
+
// Move text left (w/wrap), increase hue
if((--textX) < textMin) textX = matrix.width();
hue += 7;
@@ -2,14 +2,15 @@
// Renders 512 colors on a 16x32 RGB LED matrix.
// Library supports 4096 colors, but there aren't that many pixels!
-#include "RGBmatrixPanel.h"
+#include <Adafruit_GFX.h> // Core graphics library
+#include <RGBmatrixPanel.h> // Hardware-specific library
-#define A A0
-#define B A1
-#define C A2
#define CLK 8 // MUST be on PORTB!
#define LAT A3
#define OE 9
+#define A A0
+#define B A1
+#define C A2
RGBmatrixPanel matrix(A, B, C, CLK, LAT, OE, false);
void setup() {
@@ -2,14 +2,15 @@
// Demonstrates the drawing abilities of the RGBmatrixPanel library.
// For 16x32 RGB LED matrix.
-#include "RGBmatrixPanel.h"
+#include <Adafruit_GFX.h> // Core graphics library
+#include <RGBmatrixPanel.h> // Hardware-specific library
-#define A A0
-#define B A1
-#define C A2
#define CLK 8 // MUST be on PORTB!
#define LAT A3
#define OE 9
+#define A A0
+#define B A1
+#define C A2
RGBmatrixPanel matrix(A, B, C, CLK, LAT, OE, false);
void setup() {
@@ -42,7 +43,7 @@ void setup() {
delay(500);
// fill the screen with 'black'
- matrix.fill(matrix.Color333(0, 0, 0));
+ matrix.fillScreen(matrix.Color333(0, 0, 0));
// draw some text!
matrix.setCursor(1, 0); // start at top left, with one pixel of spacing
@@ -2,7 +2,8 @@
// Demonstrates the drawing abilities of the RGBmatrixPanel library.
// For 32x32 RGB LED matrix.
-#include "RGBmatrixPanel.h"
+#include <Adafruit_GFX.h> // Core graphics library
+#include <RGBmatrixPanel.h> // Hardware-specific library
#define A A3
#define B A2
@@ -43,11 +44,12 @@ void setup() {
delay(500);
// fill the screen with 'black'
- matrix.fill(matrix.Color333(0, 0, 0));
+ matrix.fillScreen(matrix.Color333(0, 0, 0));
// draw some text!
- matrix.setCursor(1, 0); // start at top left, with one pixel of spacing
- matrix.setTextSize(1); // size 1 == 8 pixels high
+ matrix.setCursor(1, 0); // start at top left, with one pixel of spacing
+ matrix.setTextSize(1); // size 1 == 8 pixels high
+ matrix.setTextWrap(false); // Don't wrap at end of line - will do ourselves
matrix.setTextColor(matrix.Color333(7,7,7));
matrix.println(" Ada");
Oops, something went wrong.

0 comments on commit a875e9a

Please sign in to comment.