@Hans ja het klopt hoor, de sketch is niet veranderd, wat hij eigenlijk moet doen is aan het einde van de loop, weer opnieuw moet beginnen, dus als millis bij punt 8000 komt, zou hij gewoon weer met de eerste Sparkle effect te starten.
// gaat hier om type leonardo arduino
#define FASTLED_INTERNAL // just used to mute the Pragma messages when compiling
#include "FastLED.h"
const int ledPin4 = 4;// pin nummer voor breakdance leds1
const int ledPin5 = 5;// pin nummer voor breakdance leds2
int ledState4 = LOW;
int ledState5 = LOW;
unsigned long previousMillis = 0;
const long interval = 1500;
#define PIN_STRIP1 6 //dit is strip 1 op de diamant
#define PIN_STRIP2 7 //dit is strip 2 op de diamant
#define PIN_STRIP3 8 //dit zijn de leds onder de kop
#define PIN_STRIP4 9 //dit zijn de leds op de kop
#define LED_COUNT1 26 //aantal leds op de diamant in strip 1
#define LED_COUNT2 26 //aantal leds op de diamant in strip 2
#define LED_COUNT3 10 //aantal leds onder de kop
#define LED_COUNT4 31 //aantal leds op de kop
#define LED_TYPE WS2812
#define NUM_LEDS 28
CRGBPalette16 firePalette = HeatColors_p;
CRGB leds_strip1[LED_COUNT1];
CRGB leds_strip2[LED_COUNT2];
CRGB leds_strip3[LED_COUNT3];
CRGB leds_strip4[LED_COUNT4];
unsigned long currentMillis = 0;
unsigned long startMillis = 0;
void setup() {
FastLED.addLeds<LED_TYPE, PIN_STRIP1, GRB>(leds_strip1, LED_COUNT1).setCorrection(TypicalLEDStrip);
FastLED.addLeds<LED_TYPE, PIN_STRIP2, GRB>(leds_strip2, LED_COUNT2).setCorrection(TypicalLEDStrip);
FastLED.addLeds<LED_TYPE, PIN_STRIP3, RGB>(leds_strip3, LED_COUNT3).setCorrection(TypicalLEDStrip);
FastLED.addLeds<LED_TYPE, PIN_STRIP4, RGB>(leds_strip4, LED_COUNT4).setCorrection(TypicalLEDStrip);
FastLED.clear(true); // clear alle LEDs
startMillis = millis(); //start de tijd
pinMode(ledPin4, OUTPUT);
pinMode(ledPin5, OUTPUT);
}
void purpleBlackGreen() {
uint16_t sinBeat = beatsin16(20, 0, LED_COUNT1 - 1, 0, 0);
uint16_t sinBeat2 = beatsin16(20, 0, LED_COUNT1 - 1, 0, 21845);
uint16_t sinBeat3 = beatsin16(20, 0, LED_COUNT1 - 1, 0, 43690);
leds_strip1[sinBeat] = CRGB::Purple;
leds_strip1[sinBeat2] = CRGB::Black;
leds_strip1[sinBeat3] = CRGB::Green;
fadeToBlackBy(leds_strip1, LED_COUNT1, 12);
}
void purpleBlackGreen1() {
uint16_t sinBeat = beatsin16(20, 0, LED_COUNT2 - 0, 0, 0);
uint16_t sinBeat2 = beatsin16(20, 0, LED_COUNT2 - 1, 0, 21845);
uint16_t sinBeat3 = beatsin16(20, 0, LED_COUNT2 - 1, 0, 43690);
leds_strip2[sinBeat] = CRGB::Purple;
leds_strip2[sinBeat2] = CRGB::Black;
leds_strip2[sinBeat3] = CRGB::Green;
fadeToBlackBy(leds_strip2, LED_COUNT2, 12);
}
void Sparkle(CRGB ledstrip[], int ledcount, byte red, byte green, byte blue, int SpeedDelay) {
int Pixel = random(ledcount);
ledstrip[Pixel] = CRGB(red, green, blue);
FastLED.show();
delay(70);
ledstrip[Pixel] = CRGB(0, 0, 0);
}
void juggle() {
// eight colored dots, weaving in and out of sync with each other
fadeToBlackBy( leds_strip4, LED_COUNT4, 20);
byte dothue = 0;
for ( int i = 0; i < 8; i++) {
leds_strip4[beatsin16( i + 7, 0, LED_COUNT4 - 1 )] |= CHSV(dothue, 200, 255);
dothue += 32;
}
}
void juggle1() {
// eight colored dots, weaving in and out of sync with each other
fadeToBlackBy( leds_strip1, LED_COUNT1, 20);
byte dothue = 0;
for ( int i = 0; i < 10; i++) {
leds_strip1[beatsin16( i + 7, 0, LED_COUNT1 - 1 )] |= CHSV(dothue, 200, 255);
dothue += 32;
}
}
void juggle2() {
// eight colored dots, weaving in and out of sync with each other
fadeToBlackBy( leds_strip2, LED_COUNT2, 22);
byte dothue = 0;
for ( int i = 0; i < 5; i++) {
leds_strip2[beatsin16( i + 7, 0, LED_COUNT2 - 1 )] |= CHSV(dothue, 200, 255);
dothue += 32;
}
}
void runFire1() {
int a = millis();
for (int i = 0; i < NUM_LEDS; i++) {
uint8_t noise = inoise8 (0 , i * 70 - a , a / 3);
uint8_t math = abs8(i - (NUM_LEDS - 26)) * 255 / (NUM_LEDS - 0);
uint8_t index = qsub8 (noise, math);
leds_strip1[i] = ColorFromPalette (firePalette, index, 255);
}
}
void runFire2() {
int a = millis();
for (int i = 0; i < NUM_LEDS; i++) {
uint8_t noise = inoise8 (0 , i * 30 - a , a / 3);
uint8_t math = abs8(i - (NUM_LEDS - 26)) * 255 / (NUM_LEDS - 0);
uint8_t index = qsub8 (noise, math);
leds_strip2[i] = ColorFromPalette (firePalette, index, 255);
}
}
void redWhiteBlue1() {
uint16_t sinBeat = beatsin16(30, 0, LED_COUNT1 - 1, 0, 0);
uint16_t sinBeat2 = beatsin16(30, 0, LED_COUNT1 - 1, 0, 21845);
uint16_t sinBeat3 = beatsin16(30, 0, LED_COUNT1 - 1, 0, 43690);
leds_strip1[sinBeat] = CRGB::Blue;
leds_strip1[sinBeat2] = CRGB::Red;
leds_strip1[sinBeat3] = CRGB::White;
fadeToBlackBy(leds_strip1, LED_COUNT1, 5);
}
void redWhiteBlue2() {
uint16_t sinBeat = beatsin16(20, 0, LED_COUNT2 - 1, 0, 0);
uint16_t sinBeat2 = beatsin16(20, 0, LED_COUNT2 - 1, 0, 21845);
uint16_t sinBeat3 = beatsin16(20, 0, LED_COUNT2 - 1, 0, 43690);
leds_strip2[sinBeat] = CRGB::Blue;
leds_strip2[sinBeat2] = CRGB::Red;
leds_strip2[sinBeat3] = CRGB::White;
fadeToBlackBy(leds_strip2, LED_COUNT2, 5);
}
void loop()
{
currentMillis = millis(); // haal de tijd op
if ( currentMillis - startMillis > 0 && currentMillis - startMillis < 10000)
{
Sparkle(leds_strip1, LED_COUNT1, 0xff, 0xff, 0xff, 180);
Sparkle(leds_strip2, LED_COUNT2, 0xff, 0xff, 0xff, 0);
Sparkle(leds_strip3, LED_COUNT3, 0xff, 0xff, 0xff, 0);
Sparkle(leds_strip4, LED_COUNT4, 0xff, 0xff, 0xff, 0);
FastLED.setBrightness(250);
FastLED.show();
}
if ( currentMillis - startMillis > 10000 && currentMillis - startMillis < 20000)
{
EVERY_N_MILLISECONDS(50) {
runFire1();
runFire2();
FastLED.setBrightness(100);
FastLED.show();
}
fill_solid( leds_strip3, LED_COUNT3, CRGB(225, 0, 0));
fill_solid( leds_strip4, LED_COUNT4, CRGB(255, 112, 0));
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
if (ledState4 == LOW) {
ledState4 = HIGH;
} else {
ledState4 = LOW;
}
digitalWrite(ledPin4, ledState4);
}
if (ledState4 == LOW) {
digitalWrite (ledPin5, HIGH);
} else {
digitalWrite (ledPin5, LOW);
}
}
if ( currentMillis - startMillis > 20000 && currentMillis - startMillis < 30000)
{
purpleBlackGreen();
purpleBlackGreen1();
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= 1500) {
previousMillis = currentMillis;
if (ledState4 == LOW) {
ledState4 = HIGH;
fill_solid( leds_strip3, LED_COUNT3, CRGB (0, 255, 0));
} else {
ledState4 = LOW;
fill_solid( leds_strip3, LED_COUNT3, CRGB(255, 0, 255));
}
digitalWrite(ledPin4, ledState4);
}
if (ledState4 == LOW) {
digitalWrite (ledPin5, HIGH);
fill_solid( leds_strip3, LED_COUNT3, CRGB(0, 255, 0));
fill_solid( leds_strip4, LED_COUNT4, CRGB(255, 0, 255));
} else {
digitalWrite (ledPin5, LOW);
fill_solid( leds_strip3, LED_COUNT3, CRGB(255, 0, 255));
fill_solid( leds_strip4, LED_COUNT4, CRGB(0, 255, 0));
}
FastLED.setBrightness(100);
FastLED.show();
}
if ( currentMillis - startMillis > 30000 && currentMillis - startMillis < 40000)
{
digitalWrite (ledPin4, LOW);
digitalWrite (ledPin5, LOW);
juggle();
juggle1();
juggle2();
fill_solid( leds_strip3, LED_COUNT3, CRGB(0, 0, 0));
FastLED.setBrightness(150);
FastLED.show();
}
if ( currentMillis - startMillis > 40000 && currentMillis - startMillis < 50000)
{
redWhiteBlue1();
redWhiteBlue2();
FastLED.setBrightness(100);
FastLED.show();
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= 1000) {
previousMillis = currentMillis;
if (ledState4 == LOW) {
ledState4 = HIGH;
fill_solid( leds_strip3, LED_COUNT3, CRGB(255, 0, 0));
} else {
ledState4 = LOW;
fill_solid( leds_strip3, LED_COUNT3, CRGB(0, 0, 255));
}
digitalWrite(ledPin4, ledState4);
}
if (ledState4 == LOW) {
digitalWrite (ledPin5, HIGH);
fill_solid( leds_strip3, LED_COUNT3, CRGB(255, 0, 0));
fill_solid( leds_strip4, LED_COUNT4, CRGB(0, 0, 255));
} else {
digitalWrite (ledPin5, LOW);
fill_solid( leds_strip3, LED_COUNT3, CRGB(0, 0, 255));
fill_solid( leds_strip4, LED_COUNT4, CRGB(255, 0, 0));
}
}
if ( currentMillis - startMillis > 50000 && currentMillis - startMillis < 53000)
{
digitalWrite (ledPin4, LOW);
digitalWrite (ledPin5, LOW);
fill_solid( leds_strip1, LED_COUNT1, CRGB(255, 0, 0)); //Let op NEO_GRB
fill_solid( leds_strip2, LED_COUNT2, CRGB(255, 0, 0)); //Let op NEO_GRB
fill_solid( leds_strip3, LED_COUNT3, CRGB(255, 0, 0)); //Let op NEO_GRB
fill_solid( leds_strip4, LED_COUNT4, CRGB(255, 0, 0)); //Let op NEO_GRB
FastLED.setBrightness(100);
FastLED.show();
}
if ( currentMillis - startMillis > 53000 && currentMillis - startMillis < 56000)
{
fill_solid( leds_strip1, LED_COUNT1, CRGB(0, 0, 255)); //Let op NEO_GRB
fill_solid( leds_strip2, LED_COUNT2, CRGB(0, 0, 255)); //Let op NEO_GRB
fill_solid( leds_strip3, LED_COUNT3, CRGB(0, 0, 255)); //Let op NEO_GRB
fill_solid( leds_strip4, LED_COUNT4, CRGB(0, 0, 255)); //Let op NEO_GRB
FastLED.setBrightness(100);
FastLED.show();
}
if ( currentMillis - startMillis > 56000 && currentMillis - startMillis < 59000)
{
fill_solid( leds_strip1, LED_COUNT1, CRGB(0, 255, 0)); //Let op NEO_GRB
fill_solid( leds_strip2, LED_COUNT2, CRGB(0, 255, 0)); //Let op NEO_GRB
fill_solid( leds_strip3, LED_COUNT3, CRGB(0, 255, 0)); //Let op NEO_GRB
fill_solid( leds_strip4, LED_COUNT4, CRGB(0, 255, 0)); //Let op NEO_GRB
FastLED.setBrightness(100);
FastLED.show();
}
if ( currentMillis - startMillis > 59000 && currentMillis - startMillis < 62000)
{
fill_solid( leds_strip1, LED_COUNT1, CRGB(255, 255, 0)); //Let op NEO_GRB
fill_solid( leds_strip2, LED_COUNT2, CRGB(255, 255, 0)); //Let op NEO_GRB
fill_solid( leds_strip3, LED_COUNT3, CRGB(255, 255, 0)); //Let op NEO_GRB
fill_solid( leds_strip4, LED_COUNT4, CRGB(255, 255, 0)); //Let op NEO_GRB
FastLED.setBrightness(100);
FastLED.show();
}
if ( currentMillis - startMillis > 62000 && currentMillis - startMillis < 65000)
{
fill_solid( leds_strip1, LED_COUNT1, CRGB(0, 255, 255)); //Let op NEO_GRB
fill_solid( leds_strip2, LED_COUNT2, CRGB(0, 255, 255)); //Let op NEO_GRB
fill_solid( leds_strip3, LED_COUNT3, CRGB(0, 255, 255)); //Let op NEO_GRB
fill_solid( leds_strip4, LED_COUNT4, CRGB(0, 255, 255)); //Let op NEO_GRB
FastLED.setBrightness(100);
FastLED.show();
}
if ( currentMillis - startMillis > 65000 && currentMillis - startMillis < 68000)
{
fill_solid( leds_strip1, LED_COUNT1, CRGB(255, 0, 255)); //Let op NEO_GRB
fill_solid( leds_strip2, LED_COUNT2, CRGB(255, 0, 255)); //Let op NEO_GRB
fill_solid( leds_strip3, LED_COUNT3, CRGB(255, 0, 255)); //Let op NEO_GRB
fill_solid( leds_strip4, LED_COUNT4, CRGB(255, 0, 255)); //Let op NEO_GRB
FastLED.setBrightness(100);
FastLED.show();
}
if ( currentMillis - startMillis > 68000 && currentMillis - startMillis < 71000)
{
fill_solid( leds_strip1, LED_COUNT1, CRGB(0, 0, 255)); //Let op NEO_GRB
fill_solid( leds_strip2, LED_COUNT2, CRGB(0, 0, 255)); //Let op NEO_GRB
fill_solid( leds_strip3, LED_COUNT3, CRGB(255, 255, 255)); //Let op NEO_GRB
fill_solid( leds_strip4, LED_COUNT4, CRGB(255, 0, 0)); //Let op NEO_GRB
FastLED.setBrightness(100);
FastLED.show();
}
if (millis >= 71000)
{
fill_solid( leds_strip1, LED_COUNT1, CRGB(0, 0, 0)); //Let op NEO_GRB
fill_solid( leds_strip2, LED_COUNT2, CRGB(0, 0, 0)); //Let op NEO_GRB
fill_solid( leds_strip3, LED_COUNT3, CRGB(0, 0, 0)); //Let op NEO_GRB
fill_solid( leds_strip4, LED_COUNT4, CRGB(0, 0, 0)); //Let op NEO_GRB
FastLED.setBrightness(100);
FastLED.show();
startMillis = 0; //start opnieuw
currentMillis = 0; //start opnieuw
return; // toegevoegd
}
}