Advertisement
marmil

lighthouse_beacon_v1

Nov 17th, 2015
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.06 KB | None | 0 0
  1. //***************************************************************
  2. // rotating beacon for lighthouse emulation
  3. // Marc Miller, Nov 2015
  4. //***************************************************************
  5.  
  6. #include "FastLED.h"
  7. #define LED_TYPE NEOPIXEL
  8. #define DATA_PIN 6
  9. //#define CLOCK_PIN 13
  10. #define NUM_LEDS 12
  11. //#define COLOR_ORDER GRB
  12. #define BRIGHTNESS 255
  13. CRGB leds[NUM_LEDS];
  14.  
  15. int8_t pixelPos = 0;  // Initial position of light.
  16. int8_t pixelRamp = 2;  // Number of pixels ramping up/down to pixelPos.
  17. int8_t fadeRate = 180;  // Fade rate for ramp up/down.
  18. int8_t hue = 42;  // Light color
  19. int8_t sat = 190;  // Saturation
  20. int8_t val = BRIGHTNESS;  // Max brightness of light
  21. uint16_t holdTime = 500;  // Milliseconds to hold position before advancing
  22. int8_t delta = 1;  // Advance rate.  (Use negative value for reverse.)
  23.  
  24. unsigned long currentMillis = 0;  // Used to store current sketch time
  25. unsigned long previousMillis = 0;  // Used to store last time
  26.  
  27.  
  28. //---------------------------------------------------------------
  29. void setup() {
  30.   //FastLED.addLeds<LED_TYPE, DATA_PIN, CLOCK_PIN, COLOR_ORDER>(leds, NUM_LEDS);
  31.   FastLED.addLeds<LED_TYPE, DATA_PIN>(leds, NUM_LEDS);
  32.   FastLED.setBrightness(BRIGHTNESS);
  33. }
  34.  
  35. //---------------------------------------------------------------
  36. void loop() {  // START MAIN LOOP
  37.  
  38.   // Draw ramp up/down pixels
  39.   for (int i = pixelRamp; i > 0; i--) {
  40.     leds[(pixelPos + i + NUM_LEDS) % NUM_LEDS] = CHSV(hue,sat,val);
  41.     leds[(pixelPos - i + NUM_LEDS) % NUM_LEDS] = CHSV(hue,sat,val);
  42.     fadeToBlackBy( leds, NUM_LEDS, fadeRate );  // creates outward fade
  43.   }
  44.  
  45.   // Draw main light position (at max brightness, no fade)
  46.   leds[(pixelPos + NUM_LEDS) % NUM_LEDS] = CHSV(hue,sat,val);
  47.  
  48.   // Show the pixels
  49.   FastLED.show();  // Show the pixels
  50.  
  51.   // Advance position based hold time. Delta determines direction.
  52.   currentMillis = millis();
  53.   if ((currentMillis - previousMillis) > holdTime) {
  54.     pixelPos = ((pixelPos + delta + NUM_LEDS) % NUM_LEDS);
  55.     previousMillis = currentMillis;
  56.   }
  57.  
  58. }  // END MAIN LOOP
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement