#include <Adafruit_GFX.h>
#include <Adafruit_NeoMatrix.h>
#include <Adafruit_NeoPixel.h>
#define NEO_PIN 6 // Neopixel pin
#define GND_PIN 9 // Signal pin used as ground
#define GND_PIN2 1 // Signal pin used as ground
#define SPEED_PIN A4 // Analog (ADC) input pin to read value of speed potentiometer
#define COLOR_PIN A5 // Analog (ADC) input pin to read value of color potentiometer
#define MAX_BRIGHTNESS 50 // Maximum Neopixel brightness
#define UP_STEPS 5 // Increasing brightness steps out of the total number of steps (smaller than half total => fast rise, slow decay)
#define TOTAL_STEPS 40 // Total number of increasing/deeasing steps
#define SPEED_DIVIDER 30 // Used to divide the value of the speed ADC readout to calculate iteration delay
const int heart[] = { // Heart bitmap
0, 1, 1, 0, 1, 1, 0, 0,
1, 1, 1, 1, 1, 1, 1, 0,
1, 1, 1, 1, 1, 1, 1, 0,
1, 1, 1, 1, 1, 1, 1, 0,
0, 1, 1, 1, 1, 1, 0, 0,
0, 0, 1, 1, 1, 0, 0, 0,
0, 0, 0, 1, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0
};
Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(4, 4, 2, 2, NEO_PIN,
NEO_TILE_TOP + NEO_TILE_LEFT + NEO_TILE_COLUMNS + NEO_TILE_ZIGZAG +
NEO_MATRIX_TOP + NEO_MATRIX_LEFT + NEO_MATRIX_ROWS + NEO_MATRIX_ZIGZAG,
NEO_GRB + NEO_KHZ800);
void setup() {
matrix.begin();
matrix.setBrightness(40);
pinMode(GND_PIN, OUTPUT);
digitalWrite(GND_PIN, LOW); // Lazy ground
pinMode(GND_PIN2, OUTPUT);
digitalWrite(GND_PIN2, LOW); // Lazy ground
pinMode(SPEED_PIN, INPUT);
pinMode(COLOR_PIN, INPUT);
}
void loop() {
int i, j;
int brightness;
int color;
for (i = 0; i < TOTAL_STEPS; i++) {
if (i < UP_STEPS)
brightness = MAX_BRIGHTNESS * i / UP_STEPS;
else
brightness = MAX_BRIGHTNESS * (TOTAL_STEPS - i - 1) / (TOTAL_STEPS - UP_STEPS);
matrix.setBrightness(brightness);
color = analogRead(COLOR_PIN) / 4;
for (j = 0; j < 64; j++) {
matrix.drawPixel(j / 8, j % 8, Wheel(color)*heart[j]);
}
matrix.show();
delay(analogRead(SPEED_PIN) / SPEED_DIVIDER);
}
}
uint32_t Wheel(byte WheelPos) { // Courtesy of multiple Adafruit examples
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);
}
}
Comments