Skip to content

Instantly share code, notes, and snippets.

@chemdoc77
Last active March 13, 2022 23:33
Show Gist options
  • Save chemdoc77/5d16cb887ac53a6f3fb52574a879a543 to your computer and use it in GitHub Desktop.
Save chemdoc77/5d16cb887ac53a6f3fb52574a879a543 to your computer and use it in GitHub Desktop.
CD77_FastLED_millis_replaces_delay - Replaces delays with FastLED EVERY_N_MILLIS function
/* EVERY_N_MILLIS_I used to replace delay by Chemdoc77
Updated 20220313- replaced EVERY_N_MILLIS with EVERY_N_MILLIS_I
Note: When using the N_Millis FastLED function in a void funcition, you must use
EVERY_N_MILLIS_I and NOT EVERY_N_MILLIS.
*/
#include "FastLED.h"
#define NUM_LEDS 24
#define DATA_PIN 6
#define LED_TYPE NEOPIXEL
int brightness = 30; // Adjust from 0 to 255 to set matrix brightness.
uint8_t x=0;
CRGB leds[NUM_LEDS];
void setup() {
delay(500); // power-up safety delay
FastLED.addLeds<LED_TYPE, DATA_PIN>(leds, NUM_LEDS);
FastLED.setBrightness(brightness);
FastLED.setMaxPowerInVoltsAndMilliamps(5, 1000);
set_max_power_indicator_LED(13);
fill_solid(leds, NUM_LEDS, CRGB::Black);
FastLED.show();
}
void loop() {
//CD77_colorwipe_dot_nodelay(CRGB::Blue, 150);
CD77_colorwipe_nodelay(CRGB::Red, 150);
delay(1000);
fill_solid(leds,NUM_LEDS, CRGB::Black);
FastLED.show();
}
//===================================================
void CD77_colorwipe_dot_nodelay(CRGB color, uint32_t wait) { //without delay
EVERY_N_MILLIS_I( wait_time, wait) {
wait_time.setPeriod( wait );
x++;
if (x >= NUM_LEDS) {x = 0;}
fill_solid(leds,NUM_LEDS, CRGB::Black);
leds[x] = color;
FastLED.show();
}
}
void CD77_colorwipe_dot(CRGB color, uint8_t wait) { // with delay
for (uint8_t i = 0; i <NUM_LEDS; i++) {
leds[i] = color;
FastLED.show();
delay(wait);
leds[i] = CRGB::Black;
FastLED.show();
}
}
void CD77_colorwipe_nodelay(CRGB color, uint32_t wait) { //without delay
EVERY_N_MILLIS_I( wait_time, wait) {
wait_time.setPeriod( wait );
x++;
if (x >= NUM_LEDS) {x = 0;}
leds[x] = color;
FastLED.show();
}
}
void CD77_colorwipe(CRGB color, uint8_t wait) { //with delay
for (uint8_t i = 0; i <NUM_LEDS; i++) {
leds[i] = color;
FastLED.show();
delay(wait);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment