SHARE
TWEET

Untitled

a guest Jul 22nd, 2019 47 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.   THIS SKETCH TRANSPORMS 4-COLOR RGBW LEDS INTO 2 3-COLOR RGB LEDS,
  3.   SO YOU CAN USE FASTLED (WHICH AS OF NOW, HAS NO RGBW SUPPORT), TO
  4.   CONTROL RGBW LEDS
  5.  
  6. */
  7.  
  8. #include <FastLED.h>
  9.  
  10. #define NUM_LEDS 16
  11.  
  12. /*
  13.    for every 3 rgbw leds, we need 4 rgb leds.
  14.    to get rgbw count from rgb, do (count/4)*3, and roud it down
  15.    to get rgb count from rgbw, do (count/3)*4, and round it up
  16. */
  17.  
  18. #define NUM_LEDS_RGBW 10
  19.  
  20.  
  21. #define LED_PIN 12
  22. CRGB leds[NUM_LEDS];
  23.  
  24. void setup() {
  25.   FastLED.addLeds<NEOPIXEL, LED_PIN>(leds, NUM_LEDS);
  26.   Serial.begin(115200);
  27. }
  28. void loop() {
  29.  
  30.   for (int i = 0; i < NUM_LEDS_RGBW; i++) {
  31.     setRGBW(i, 1, 0, 0, 0);
  32.     //leds[i][0] = 5;
  33.     //leds[i] = CRGB(5,0,0);
  34.     FastLED.show();
  35.     delay(100);
  36.   }
  37.   delay(3000);
  38.   //while (1);
  39.   for (int i = 0; i < NUM_LEDS_RGBW; i++) {
  40.     setRGBW(i, 0, 9, 0, 0);
  41.     FastLED.show();
  42.     delay(100);
  43.   }
  44.   delay(3000);
  45.   for (int i = 0; i < NUM_LEDS_RGBW; i++) {
  46.     setRGBW(i, 0, 0, 9, 0);
  47.     FastLED.show();
  48.     delay(100);
  49.   }
  50.  
  51.   delay(3000);
  52.   for (int i = 0; i < NUM_LEDS_RGBW; i++) {
  53.     setRGBW(i, 0, 0, 0, 9);
  54.     FastLED.show();
  55.     delay(100);
  56.   }
  57.  
  58.  
  59. }
  60.  
  61.  
  62. void setRGBW(int led, byte r, byte g, byte b, byte w) {
  63.   //takes r,g,b,w for 4-color LEDs and transfers them into 3-color array
  64.   //to use with fastled
  65.   int segment = int((led / 3.0) * 4.0);
  66.  
  67.  
  68.  
  69.   switch ( led % 3) {
  70.     case 0:  //first
  71.       leds[segment][0] = r;
  72.       leds[segment][1] = g;
  73.       leds[segment][2] = b;
  74.       leds[segment + 1][1] = w;
  75.  
  76.       break;
  77.     case 1: //second
  78.       leds[segment][0] = g;
  79.       leds[segment][2] = r;
  80.       leds[segment + 1][0] = w;
  81.       leds[segment + 1][1] = b;
  82.  
  83.       break;
  84.     case 2: //third
  85.       leds[segment][2] = g;
  86.       leds[segment + 1][0] = b;
  87.       leds[segment + 1][1] = r;
  88.       leds[segment + 1][2] = w;
  89.  
  90.       break;
  91.   }
  92.  
  93.  
  94. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top