Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Police lights
#include "FastLED.h"
// #include <Adafruit_NeoPixel.h>
#define NUM_LEDS 28
#define Data_Pin 3
// #define CLK_PIN 8
#define chipset WS2812
// #define COLOR_ORDER GRB
#define BRIGHTNESS 100
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(3, 4, 80, CRGB::WhiteSmoke); // clockwise on a ring
// 1st value is the number of pixels that are 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 (3, 4, 50, CRGB::Wheat); // 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