Advertisement
Guest User

Ship lights test

a guest
Apr 12th, 2019
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. #include "FastLED.h"
  2. #define NUM_LEDS 24
  3. CRGB leds[NUM_LEDS];
  4. #define PIN 3
  5.  
  6. void setup()
  7. {
  8. FastLED.addLeds<WS2811, PIN, GRB>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
  9. }
  10.  
  11. void loop() {
  12. FadeInOut(0xF8, 0xF8, 0xFF);
  13. }
  14.  
  15. void FadeInOut(byte red, byte green, byte blue){
  16. float r, g, b;
  17.  
  18. for(int k = 250; k < 256; k=k+1) {
  19. r = (k/256.0)*red;
  20. g = (k/256.0)*green;
  21. b = (k/256.0)*blue;
  22. setAll(r,g,b);
  23.  
  24. }
  25.  
  26. for(int k = 255; k >= 250; k=k-2) {
  27. r = (k/256.0)*red;
  28. g = (k/256.0)*green;
  29. b = (k/256.0)*blue;
  30. setAll(r,g,b);
  31.  
  32. }
  33. }
  34.  
  35. void showStrip() {
  36. #ifdef ADAFRUIT_NEOPIXEL_H
  37. // NeoPixel
  38. strip.show();
  39. #endif
  40. #ifndef ADAFRUIT_NEOPIXEL_H
  41. // FastLED
  42. FastLED.show();
  43. #endif
  44. }
  45.  
  46. void setPixel(int Pixel, byte red, byte green, byte blue) {
  47. #ifdef ADAFRUIT_NEOPIXEL_H
  48. // NeoPixel
  49. strip.setPixelColor(Pixel, strip.Color(red, green, blue));
  50. #endif
  51. #ifndef ADAFRUIT_NEOPIXEL_H
  52. // FastLED
  53. leds[Pixel].r = red;
  54. leds[Pixel].g = green;
  55. leds[Pixel].b = blue;
  56. #endif
  57. }
  58.  
  59. void setAll(byte red, byte green, byte blue) {
  60. for(int i = 0; i < NUM_LEDS; i++ ) {
  61. setPixel(i, red, green, blue);
  62. }
  63. showStrip();
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement