Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //***************************************************************
- // rotating beacon for lighthouse emulation
- // Marc Miller, Nov 2015
- //***************************************************************
- #include "FastLED.h"
- #define LED_TYPE NEOPIXEL
- #define DATA_PIN 6
- //#define CLOCK_PIN 13
- #define NUM_LEDS 12
- //#define COLOR_ORDER GRB
- #define BRIGHTNESS 255
- CRGB leds[NUM_LEDS];
- int8_t pixelPos = 0; // Initial position of light.
- int8_t pixelRamp = 2; // Number of pixels ramping up/down to pixelPos.
- int8_t fadeRate = 180; // Fade rate for ramp up/down.
- int8_t hue = 42; // Light color
- int8_t sat = 190; // Saturation
- int8_t val = BRIGHTNESS; // Max brightness of light
- uint16_t holdTime = 500; // Milliseconds to hold position before advancing
- int8_t delta = 1; // Advance rate. (Use negative value for reverse.)
- unsigned long currentMillis = 0; // Used to store current sketch time
- unsigned long previousMillis = 0; // Used to store last time
- //---------------------------------------------------------------
- void setup() {
- //FastLED.addLeds<LED_TYPE, DATA_PIN, CLOCK_PIN, COLOR_ORDER>(leds, NUM_LEDS);
- FastLED.addLeds<LED_TYPE, DATA_PIN>(leds, NUM_LEDS);
- FastLED.setBrightness(BRIGHTNESS);
- }
- //---------------------------------------------------------------
- void loop() { // START MAIN LOOP
- // Draw ramp up/down pixels
- for (int i = pixelRamp; i > 0; i--) {
- leds[(pixelPos + i + NUM_LEDS) % NUM_LEDS] = CHSV(hue,sat,val);
- leds[(pixelPos - i + NUM_LEDS) % NUM_LEDS] = CHSV(hue,sat,val);
- fadeToBlackBy( leds, NUM_LEDS, fadeRate ); // creates outward fade
- }
- // Draw main light position (at max brightness, no fade)
- leds[(pixelPos + NUM_LEDS) % NUM_LEDS] = CHSV(hue,sat,val);
- // Show the pixels
- FastLED.show(); // Show the pixels
- // Advance position based hold time. Delta determines direction.
- currentMillis = millis();
- if ((currentMillis - previousMillis) > holdTime) {
- pixelPos = ((pixelPos + delta + NUM_LEDS) % NUM_LEDS);
- previousMillis = currentMillis;
- }
- } // END MAIN LOOP
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement