Last active
February 4, 2019 11:40
-
-
Save chemdoc77/f140d6275f90c65e7453569b3e9ad648 to your computer and use it in GitHub Desktop.
The following sketch contains various functions based on the CD77_Police_Lights_One functions, from my original sketch in GitHub, CD77_police_lights. It includes automatic color change.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* CD77_police_light_one_auto_color_change by Chemdoc77 | |
Includes new functions for various number of pixels that are on in a group and for forward and reverse directions. | |
Includes automatic color change with seconds input. See line 42 for this variable. | |
******** Version 20190203 ************* | |
This code is based on the police_lightsONE and police_lightsALL code: | |
in Funkboxing by Teldredge at: | |
http://funkboxing.com/wordpress/wp-content/_postfiles/sk_qLEDFX_POST.ino | |
This sketch is one function from the following sketch in GitHub at: | |
https://github.com/chemdoc77/CD77_FastLED/tree/master/CD77_police_lights | |
It uses the out of bounds concept and code from the FastLED XYMatrix Example at: | |
https://github.com/FastLED/FastLED/blob/master/examples/XYMatrix/XYMatrix.ino | |
*/ | |
#include "FastLED.h" | |
#define NUM_LEDS 24 | |
#define Data_Pin 6 | |
#define chipset NEOPIXEL | |
#define BRIGHTNESS 40 | |
int x = 0; | |
int xx = NUM_LEDS-1; | |
//Timing Stuff | |
#define NUM_MODES 1 // note: modes start at 0. | |
int landingMode = 0; //FIRST ACTIVE MODE | |
//************************************************************* | |
int wait_ColorMode =5; // Change this number to change time each color is on. | |
// It is in seconds. | |
//************************************************************** | |
// From the FastLED XYMatrix Example out of bounds code: | |
CRGB leds_plus_safety_pixel[ NUM_LEDS + 4]; | |
CRGB* const leds( leds_plus_safety_pixel + 4); | |
//=============================== | |
void setup() { | |
delay(1000); // power-up safety delay | |
FastLED.addLeds<chipset, Data_Pin>(leds, NUM_LEDS); | |
FastLED.setBrightness(BRIGHTNESS); | |
FastLED.setMaxPowerInVoltsAndMilliamps(5,1500); // sets max amperage to 1500 milliamps (1.5 amps) | |
set_max_power_indicator_LED(13); | |
} | |
void loop(){ | |
EVERY_N_SECONDS(wait_ColorMode){ | |
landingMode++; | |
if (landingMode > NUM_MODES) {landingMode = 0;} | |
} | |
switch (landingMode) { | |
case 0:cd77_police_lights_one_modified_n_dots(2, 4, 60, CRGB::Red); break; // number of dots, number of segments, speed of animation and CRGB color. | |
case 1:cd77_police_lights_one_modified_n_dots(2, 4, 30, CRGB::Blue); break; | |
} | |
} | |
//Sketch Functions ================================ | |
void cd77_police_lights_one_modified_n_dots(int numb_dots, int segments, uint16_t wait1, CRGB color){ | |
EVERY_N_MILLIS_I( ship_time, 60){ | |
ship_time.setPeriod(wait1 ); | |
x++; | |
if (x >= NUM_LEDS) {x = 0;} | |
fill_solid(leds,NUM_LEDS, CRGB::Black); | |
for (int z=0; z< segments;z++){ | |
int y = x + (z*NUM_LEDS)/segments; | |
if ((x + (z*NUM_LEDS)/segments) > NUM_LEDS-1) {y = (x + (z*NUM_LEDS)/segments)%NUM_LEDS; } | |
for (int dots=0; dots<numb_dots; dots++){ | |
//leds[y]= color; | |
leds[y-dots]= color; | |
} | |
FastLED.show(); | |
} | |
} | |
} | |
//==================== | |
void cd77_police_lights_one_modified_n_dots_reverse(int numb_dots, int segments, uint16_t wait1,CRGB color){ | |
EVERY_N_MILLIS_I( ship_time, 60){ | |
ship_time.setPeriod(wait1); | |
xx--; | |
if (xx <=0) {xx = NUM_LEDS-1;} | |
fill_solid(leds,NUM_LEDS, CRGB::Black); | |
for (int z=0; z< segments;z++){ | |
int y = xx + (z*NUM_LEDS)/segments; | |
if ((xx + (z*NUM_LEDS)/segments) > NUM_LEDS-1) {y = (xx + (z*NUM_LEDS)/segments)%NUM_LEDS; } | |
for (int dots=0; dots<numb_dots; dots++){ | |
//leds[y]= color; | |
leds[y-dots]= color; | |
} | |
FastLED.show(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment