Advertisement
kartonman

Pallete blending

Aug 31st, 2021
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. #include <FastLED.h>
  2.  
  3. #define NUM_LEDS 18
  4. #define LED_PIN 2
  5.  
  6. CRGB leds[NUM_LEDS];
  7.  
  8. uint8_t colorIndex[NUM_LEDS];
  9. uint8_t whichPalette = 0;
  10.  
  11. DEFINE_GRADIENT_PALETTE( greenblue_gp ) {
  12. 0, 0, 194, 255, //light blue
  13. 46, 3, 0, 246, //dark blue
  14. 176, 55, 222, 70, //bright green
  15. 255, 0, 194, 255 //light blue
  16. };
  17.  
  18. DEFINE_GRADIENT_PALETTE( orangepink_gp ) {
  19. 0, 255, 100, 0, //orange
  20. 90, 255, 0, 255, //magenta
  21. 150, 255, 100, 0, //orange
  22. 255, 255, 100, 0 //orange
  23. };
  24.  
  25. DEFINE_GRADIENT_PALETTE( browngreen_gp ) {
  26. 0, 6, 255, 0, //green
  27. 71, 0, 255, 153, //bluegreen
  28. 122, 200, 200, 200, //gray
  29. 181, 110, 61, 6, //brown
  30. 255, 6, 255, 0 //green
  31. };
  32.  
  33. CRGBPalette16 currentPalette(greenblue_gp);
  34. CRGBPalette16 targetPalette(orangepink_gp);
  35.  
  36. void setup() {
  37. FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
  38. FastLED.setBrightness(50);
  39.  
  40. Serial.begin(57600);
  41.  
  42. //Fill the colorIndex array with random numbers
  43. for (int i = 0; i < NUM_LEDS; i++) {
  44. colorIndex[i] = random8();
  45. }
  46. }
  47.  
  48. void loop() {
  49.  
  50. // Color each pixel from the palette using the index from colorIndex[]
  51. for (int i = 0; i < NUM_LEDS; i++) {
  52. leds[i] = ColorFromPalette(currentPalette, colorIndex[i]);
  53. }
  54.  
  55. nblendPaletteTowardPalette( currentPalette, targetPalette, 10 );
  56.  
  57. switch (whichPalette) {
  58. case 0:
  59. targetPalette = orangepink_gp;
  60. break;
  61. case 1:
  62. targetPalette = browngreen_gp;
  63. break;
  64. case 2:
  65. targetPalette = greenblue_gp;
  66. break;
  67. }
  68.  
  69. EVERY_N_SECONDS(5) {
  70. whichPalette++;
  71. if (whichPalette > 2) whichPalette = 0;
  72. Serial.println(currentPalette[0]);
  73. }
  74.  
  75. EVERY_N_MILLISECONDS(5){
  76. for (int i = 0; i < NUM_LEDS; i++) {
  77. colorIndex[i]++;
  78. }
  79. }
  80.  
  81. FastLED.show();
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement