Skip to content

Instantly share code, notes, and snippets.

@whichlight
Created November 11, 2013 18:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save whichlight/7418447 to your computer and use it in GitHub Desktop.
Save whichlight/7418447 to your computer and use it in GitHub Desktop.
RGB 32x32 LED grid programming
// colorwheel demo for RGBmatrixPanel library.
// Renders a nice circle of hues on a 32x32 RGB LED matrix.
#include <Adafruit_GFX.h> // Core graphics library
#include <RGBmatrixPanel.h> // Hardware-specific library
// If your 32x32 matrix has the SINGLE HEADER input,
// use this pinout:
#define CLK 8 // MUST be on PORTB!
#define OE 9
#define LAT 10
#define A A0
#define B A1
#define C A2
#define D A3
// If your matrix has the DOUBLE HEADER input, use:
//#define CLK 8 // MUST be on PORTB!
//#define LAT 9
//#define OE 10
//#define A A3
//#define B A2
//#define C A1
//#define D A0
RGBmatrixPanel matrix(A, B, C, D, CLK, LAT, OE, false);
int col;
void setup() {
int x, y, hue;
float dx, dy, d;
uint8_t sat, val;
uint16_t c;
matrix.begin();
for(y=0; y < matrix.width(); y++) {
dy = 15.5 - (float)y;
for(x=0; x < matrix.height(); x++) {
dx = 15.5 - (float)x;
d = dx * dx + dy * dy;
if(d <= (16.5 * 16.5)) { // Inside the circle(ish)?
hue = (int)((atan2(-dy, dx) + PI) * 1536.0 / (PI * 2.0));
d = sqrt(d);
if(d > 15.5) {
// Do a little pseudo anti-aliasing along perimeter
sat = 255;
val = (int)((1.0 - (d - 15.5)) * 255.0 + 0.5);
} else
{
// White at center
sat = (int)(d / 15.5 * 255.0 + 0.5);
val = 255;
}
c = matrix.ColorHSV(hue, sat, val, true);
} else {
c = 0;
}
// c = matrix.ColorHSV(0, 255, 100, true);
matrix.drawPixel(x, y, matrix.Color444(10, 0, 0));
}
}
}
void loop() {
// do nothing
col++;
col = col % 16;
for(int y=0; y < matrix.width(); y++) {
for(int x=0; x < matrix.height(); x++) {
int xx = (x + col);
int yy = (y + col);
matrix.drawPixel(x, y, matrix.Color444(((xx) % 16)/2, ((xx + yy) % 16)/2, ((yy) % 16)/2));
//matrix.drawPixel(x, y, matrix.Color444(5, 5, 5));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment