Skip to content

Instantly share code, notes, and snippets.

@koalahamlet
Created November 7, 2024 05:46
Show Gist options
  • Save koalahamlet/a97ac6277e9251da6d9b5956f83dfc93 to your computer and use it in GitHub Desktop.
Save koalahamlet/a97ac6277e9251da6d9b5956f83dfc93 to your computer and use it in GitHub Desktop.
color tester for a strip.
#include <FastLED.h>
#include <stdio.h>
#include <SPI.h>
#define LED_PIN_DATA 11
#define LED_PIN_CLOCK 13
#define NUM_LEDS 128 // Adjust this to the number of LEDs in your strip
#define BRIGHTNESS 155
#define POT_PIN_RED A3
#define POT_PIN_GREEN A0
#define POT_PIN_BLUE A6
#define LED_TYPE APA102
#define COLOR_ORDER BGR
CRGB leds[NUM_LEDS];
void setup() {
delay(1000);
FastLED.addLeds<LED_TYPE, LED_PIN_DATA, LED_PIN_CLOCK, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(UncorrectedColor);
FastLED.setBrightness(BRIGHTNESS);
FastLED.setDither(false);
FastLED.setMaxRefreshRate(0, false);
Serial.begin(9600); // Initialize serial communication for debugging
}
void loop() {
updateColors();
FastLED.show();
}
void updateColors() {
// Read the values from potentiometers
int potGreenValue = analogRead(POT_PIN_GREEN);
int potBlueValue = analogRead(POT_PIN_BLUE);
int potRedValue = analogRead(POT_PIN_RED);
// Map these values to the range 0-255
int redValue = constrain(map(potRedValue, 200, 900, 0, 255),0,255);
int greenValue = constrain(map(potGreenValue, 200, 900, 0, 255),0,255);
int blueValue = constrain(map(potBlueValue, 200, 900, 0, 255),0,255);
// Debugging output
Serial.print("Red: ");
Serial.print(redValue);
Serial.print(" Green: ");
Serial.print(greenValue);
Serial.print(" Blue: ");
Serial.println(blueValue);
// Set all LEDs to the color with Red fixed, and Green and Blue controlled by potentiometers
for (int i = 0; i < NUM_LEDS; i++) {
leds[i] = CRGB(redValue, greenValue, blueValue); // Fixed Red at 255, adjustable Green and Blue
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment