Skip to content

Instantly share code, notes, and snippets.

@deantonious
Created February 17, 2019 22:20
Show Gist options
  • Save deantonious/1a6ad57690626e3e2c49412c230e2f18 to your computer and use it in GitHub Desktop.
Save deantonious/1a6ad57690626e3e2c49412c230e2f18 to your computer and use it in GitHub Desktop.
APA102 LED Demo
#include <FastLED.h>
#define NUM_LEDS 1
#define DATA_PIN 3
#define CLOCK_PIN 2
CRGB leds[NUM_LEDS];
int wheelStatus = 0;
float brightness = 1.0;
void setup() {
FastLED.addLeds<APA102, DATA_PIN, CLOCK_PIN, BGR>(leds, NUM_LEDS);
}
void loop() {
for(int i = 0; i < NUM_LEDS; i++){
leds[i] = Wheel((i + wheelStatus) & 255);
}
FastLED.show();
wheelStatus++;
if (wheelStatus == 256)
wheelStatus = 0;
delay(100);
}
CRGB Wheel(byte WheelPos) {
WheelPos = 255 - WheelPos;
if (WheelPos < 85) {
return CRGB((255 - WheelPos * 3) * brightness, 0, (WheelPos * 3) * brightness);
}
if (WheelPos < 170) {
WheelPos -= 85;
return CRGB(0, (WheelPos * 3) * brightness, (255 - WheelPos * 3) * brightness);
}
WheelPos -= 170;
return CRGB((WheelPos * 3) * brightness, (255 - WheelPos * 3) * brightness, 0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment