Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <FastLED.h>
- #define LED_PIN 5 // Pin number connected to the LED strip
- #define NUM_LEDS 60 // Number of LEDs in the strip
- #define LED_TYPE WS2812B // Type of the LED strip
- #define COLOR_ORDER GRB // Color order of the LED strip
- CRGB leds[NUM_LEDS]; // Define an array of CRGB objects representing each LED
- // Function to convert color temperature to RGB values
- void colorTemperatureToRGB(uint16_t kelvin, uint8_t& r, uint8_t& g, uint8_t& b) {
- // Calculate the red component
- if (kelvin <= 66) {
- r = 255;
- } else {
- double tempRed = 329.698727446 * pow((kelvin - 60), -0.1332047592);
- r = constrain(tempRed, 0, 255);
- }
- // Calculate the green component
- if (kelvin <= 66) {
- double tempGreen = 99.4708025861 * log(kelvin) - 161.1195681661;
- g = constrain(tempGreen, 0, 255);
- } else {
- double tempGreen = 288.1221695283 * pow((kelvin - 60), -0.0755148492);
- g = constrain(tempGreen, 0, 255);
- }
- // Calculate the blue component
- if (kelvin >= 66) {
- b = 255;
- } else if (kelvin <= 19) {
- b = 0;
- } else {
- double tempBlue = 138.5177312231 * log(kelvin - 10) - 305.0447927307;
- b = constrain(tempBlue, 0, 255);
- }
- }
- void setup() {
- FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS); // Initialize the LED strip
- }
- void loop() {
- // Set color temperature to daylight (5500K to 6500K)
- uint16_t kelvin = 6000; // You can adjust this value to your desired color temperature
- // Convert color temperature to RGB values
- uint8_t r, g, b;
- colorTemperatureToRGB(kelvin, r, g, b);
- // Set all LEDs to the calculated daylight color
- fill_solid(leds, NUM_LEDS, CRGB(r, g, b));
- // Show the updated LEDs
- FastLED.show();
- // Add a delay to control the speed of color changes
- delay(1000); // 1000 milliseconds = 1 second
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement