Guest User

Untitled

a guest
Nov 21st, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.44 KB | None | 0 0
  1. #include <FastLED.h>
  2.  
  3. #define SENSOR_PIN 6
  4.  
  5. #define LED_PIN 3
  6. #define NUM_LEDS 80
  7. #define LED_TYPE WS2811
  8. #define COLOR_ORDER RGB
  9. CRGB leds[NUM_LEDS];
  10. #define UPDATES_PER_SECOND 100
  11.  
  12. #define NUM_SEC 16
  13. #define SEC_LEN 5
  14.  
  15. int mode = 0;
  16. int storeSensorVal = 1;
  17.  
  18. uint8_t startIndex = 0;
  19.  
  20. CRGBPalette16 currentPalette;
  21.  
  22. extern CRGBPalette16 mySunsetPalette;
  23. extern const TProgmemPalette16 mySunsetPalette_p PROGMEM;
  24.  
  25. int numModes = 7;
  26. CRGBPalette16 modes[7] = { RainbowColors_p, PartyColors_p, CloudColors_p, OceanColors_p, ForestColors_p, LavaColors_p, mySunsetPalette_p };
  27.  
  28.  
  29. void setup() {
  30. Serial.begin(9600);
  31. pinMode(SENSOR_PIN, INPUT);
  32.  
  33. delay( 3000 ); // power-up safety delay
  34. FastLED.setMaxPowerInVoltsAndMilliamps(5, 1000);
  35. FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
  36.  
  37. }
  38.  
  39. void loop() {
  40. int sensorVal = digitalRead(SENSOR_PIN);
  41.  
  42. if (sensorVal == 0 && storeSensorVal == 1) {
  43. mode++;
  44.  
  45. if (mode == numModes) {
  46. mode = 0;
  47. }
  48. }
  49.  
  50. storeSensorVal = sensorVal;
  51.  
  52. currentPalette = modes[mode];
  53.  
  54. static uint8_t startIndex = 0;
  55.  
  56. startIndex = startIndex + 1; /* motion speed */
  57.  
  58. FillLEDsFromPaletteColors(startIndex);
  59.  
  60. FastLED.show();
  61. FastLED.delay(1000 / UPDATES_PER_SECOND);
  62.  
  63. }
  64.  
  65. void FillLEDsFromPaletteColors( uint8_t colorIndex)
  66. {
  67. uint8_t brightness = 255;
  68.  
  69. for ( int i = 0; i < NUM_LEDS; i++) {
  70. int addr = (SEC_LEN * (i % NUM_SEC)) + (SEC_LEN - 1 - (floor(i/NUM_SEC)));
  71. uint8_t idx = map(addr, 0, NUM_LEDS, 0, 255) + colorIndex;
  72.  
  73. leds[addr] = ColorFromPalette( currentPalette, idx, brightness, LINEARBLEND);
  74. colorIndex += 3;
  75. }
  76. }
  77.  
  78. void lightSingleLED(int addr) {
  79. //int newAddr = ((addr % SEC_LEN) * NUM_SEC) + (floor(addr/SEC_LEN));
  80.  
  81. int newAddr = (SEC_LEN * (addr % NUM_SEC)) + (SEC_LEN - 1 - (floor(addr/NUM_SEC))); //(((SEC_LEN - 1) - (addr % SEC_LEN)) * NUM_SEC) + floor(addr/SEC_LEN);
  82. Serial.println(String(addr) + " " + String(newAddr));
  83.  
  84. for ( int i = 0; i < NUM_LEDS; i++) {
  85. if (i == newAddr) {
  86. leds[newAddr] = CRGB::Red;
  87. }
  88. else {
  89. leds[i] = CRGB::Black;
  90. }
  91. }
  92. }
  93.  
  94. const TProgmemPalette16 mySunsetPalette_p PROGMEM =
  95. {
  96. CRGB::Gray,
  97. CRGB::Gray,
  98. CRGB::Gray,
  99. CRGB::Yellow,
  100. CRGB::Gold,
  101. CRGB::Goldenrod,
  102. CRGB::Orange,
  103. CRGB::Red,
  104. CRGB::DarkRed,
  105. CRGB::Maroon,
  106. CRGB::Indigo,
  107. CRGB::Purple,
  108. CRGB::BlueViolet,
  109. CRGB::MidnightBlue,
  110. CRGB::RoyalBlue,
  111. CRGB::Blue
  112. };
Add Comment
Please, Sign In to add comment