fastLed.ino 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. ///////////////////////// FastLED ///////////////////////////////////////
  2. void beatSyncPalette() {
  3. uint8_t speed = beatsin8(BPM,0,255);
  4. uint8_t speed2 = beatsin8(1.5 * BPM,0,255);
  5. CRGB color = blend(ColorFromPalette( palette_SOLEIL,0 , 255), ColorFromPalette( palette_MER,0 , 255), speed);
  6. color = blend(color, ColorFromPalette( palette_FLAMINGO,0 , 255), speed2);
  7. fill_solid(lustre_currentPalette, 16, color);
  8. // Serial.println("beat");
  9. }
  10. void FillLEDsFromPaletteColors( CRGB leds[], int NUM_LED, CRGBPalette16 palette, uint8_t colorIndex){
  11. uint8_t brightness = 255;
  12. for( int i = 0; i < NUM_LED; i++) {
  13. leds[i] = ColorFromPalette( palette, colorIndex + sin8(i*16), 255);
  14. colorIndex += 3;
  15. }
  16. }
  17. float FadingBrightness (int FastLEDindex, float currentBrightness, float targetBrightness, int step) {
  18. //if (currentBrightness != targetBrightness) { currentBrightness += step ;}
  19. if ( (step > 0 && currentBrightness <= targetBrightness) || (step < 0 && currentBrightness >= targetBrightness) ) { currentBrightness = constrain(currentBrightness + step, 0, 255) ;}
  20. //else Serial.println("fade done");
  21. //Serial.println(currentBrightness);
  22. FastLED[FastLEDindex].showLeds((int)currentBrightness) ;
  23. return currentBrightness ;
  24. }
  25. void updateLeds(){
  26. nblendPaletteTowardPalette(lustre_currentPalette, lustre_targetPalette, 48);
  27. nblendPaletteTowardPalette(lustre_currentPalette, lustre_targetPalette, 48);
  28. nblendPaletteTowardPalette(lustre_currentPalette, lustre_targetPalette, 48);
  29. nblendPaletteTowardPalette(lustre_currentPalette, lustre_targetPalette, 48);
  30. nblendPaletteTowardPalette(lustre_currentPalette, lustre_targetPalette, 48);
  31. nblendPaletteTowardPalette(lustre_currentPalette, lustre_targetPalette, 48);
  32. if(palette_BEAT) {
  33. beatSyncPalette();
  34. }
  35. FillLEDsFromPaletteColors(lustreLeds,NUM_LEDS_LUSTRE, lustre_currentPalette, 0);
  36. // uint8_t secondHand = (millis() / 10) ;
  37. if (palette_MOVE) {
  38. if (random8(100) > 20) {
  39. int timer = millis();
  40. int delta = 2 * led_move * (sin8( timer / 9 )) * (sin8(timer / 7 )) / 65536 ; //- led_move/2
  41. FastLED[0].showLeds(lustre_currentBrightness - delta) ;
  42. //Serial.println(lustre_currentBrightness - delta);
  43. }
  44. }
  45. else {
  46. lustre_currentBrightness = FadingBrightness( 0, lustre_currentBrightness, lustre_targetBrightness ,lustre_stepBrightness);
  47. // Serial.println(lustre_currentBrightness);
  48. }
  49. nblendPaletteTowardPalette(table_currentPalette, table_targetPalette, 48);
  50. nblendPaletteTowardPalette(table_currentPalette, table_targetPalette, 48);
  51. nblendPaletteTowardPalette(table_currentPalette, table_targetPalette, 48);
  52. nblendPaletteTowardPalette(table_currentPalette, table_targetPalette, 48);
  53. nblendPaletteTowardPalette(table_currentPalette, table_targetPalette, 48);
  54. nblendPaletteTowardPalette(table_currentPalette, table_targetPalette, 48);
  55. FillLEDsFromPaletteColors(tableLeds,NUM_LEDS_TABLE, table_currentPalette, 0);
  56. table_currentBrightness = FadingBrightness( 1, table_currentBrightness, table_targetBrightness ,table_stepBrightness);
  57. }
  58. /////////////////////////////// DIMMER //////////////////////////////////////
  59. byte percent2PWM ( byte valueIn ) {
  60. return map (valueIn, 0, 100, 14, 92);
  61. }