Last active
January 27, 2019 14:29
-
-
Save chemdoc77/377b214d92c06ee4a8cc016bf7bb7b93 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.
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
// Police_Lights_One Modifed by Chemdoc77 | |
// Includes new functions for various number of pixels that are on in a group and for forward and reverse directions. | |
// ******** Version 20190126 ************* | |
/* 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; | |
// 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(){ | |
// New Functions for pixels both clockwise and counter clockwise on a ring | |
cd77_police_lights_one_modified_n_dots(2, 4, 60, CRGB::White); // clockwise on a ring | |
// 1st value is the number of pixels that are on in the group, 2nd value is the number of segments that are on, 3rd value is the delay in milliseconds and the final value is the color. | |
//cd77_police_lights_one_modified_n_dots_reverse (2, 4, 60, CRGB::White); // counter clockwise on a ring | |
//1st value is the number of pixels that are on in the group, 2nd value is the number of segments that are on, 3rd value is the delay in milliseconds and the final value is the color. | |
} | |
//Sketch Functions ================================ | |
void cd77_police_lights_one_modified( int segments, int wait,CRGB color){ | |
EVERY_N_MILLIS(wait){ | |
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; } | |
leds[y]= color; | |
} | |
FastLED.show(); | |
} | |
} | |
//======================= | |
void cd77_police_lights_one_modified_2_dots( int segments, int wait,CRGB color){ | |
EVERY_N_MILLIS(wait){ | |
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; } | |
leds[y]= color; | |
leds[y-1]= color; | |
} | |
FastLED.show(); | |
} | |
} | |
//====================== | |
void cd77_police_lights_one_modified_revese( int segments, int wait,CRGB color){ | |
EVERY_N_MILLIS(wait){ | |
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; } | |
leds[y]= color; | |
} | |
FastLED.show(); | |
} | |
} | |
//========================== | |
void cd77_police_lights_one_modified_n_dots(int numb_dots, int segments, int wait,CRGB color){ | |
EVERY_N_MILLIS(wait){ | |
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, int wait,CRGB color){ | |
EVERY_N_MILLIS(wait){ | |
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