Skip to content

Instantly share code, notes, and snippets.

@JonasDoesThings
Created June 19, 2019 16:27
Show Gist options
  • Save JonasDoesThings/10b6babc25be4e56757915ad5430c1be to your computer and use it in GitHub Desktop.
Save JonasDoesThings/10b6babc25be4e56757915ad5430c1be to your computer and use it in GitHub Desktop.
NeoMatrix Rainbow Effect
#include <Adafruit_GFX.h>
#include <Adafruit_NeoMatrix.h>
#include <Adafruit_NeoPixel.h>
#define PIN 6
Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(32, 8, PIN,
NEO_MATRIX_TOP + NEO_MATRIX_LEFT +
NEO_MATRIX_COLUMNS + NEO_MATRIX_ZIGZAG,
NEO_GRB + NEO_KHZ800);
void setup() {
matrix.begin();
matrix.setBrightness(30);
matrix.clear();
}
void loop() {
rainbowCycle();
}
void rainbowCycle() {
uint16_t i;
for(i = 0; i < 256; i++) {
for(int x = 0; x < matrix.width(); x++) {
for(int y = 0; y < matrix.height(); y++) {
matrix.drawPixel(x, y, Wheel((((x+y) * 256 / (8*32) + i) & 255)));
}
}
matrix.show();
delay(3);
}
}
// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
if(WheelPos < 85) {
return matrix.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
} else if(WheelPos < 170) {
WheelPos -= 85;
return matrix.Color(255 - WheelPos * 3, 0, WheelPos * 3);
} else {
WheelPos -= 170;
return matrix.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment