Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
54 lines (47 sloc) 1.25 KB
// 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
#define A A3
#define B A2
#define C A1
#define D A0
#define CLK 8 // MUST be on PORTB!
#define LAT 9
#define OE 10
RGBmatrixPanel matrix(A, B, C, D, CLK, LAT, OE, false);
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;
}
matrix.drawPixel(x, y, c);
}
}
}
void loop() {
// do nothing
}
Jump to Line
Something went wrong with that request. Please try again.