@marmil
Thank you very much for your help.
Hi I have managed to rotate 3 led at a time endlessly.
Below is the code. Could you please advise how to change the speed automatically (like gradually increase and decrease on time).
The code i have added ledspeed () is not working.
Please advise
#include “FastLED.h”
long loopspeed =0;
long loops =0;
int count =0;
long CurrentMillis =0;
long LastMillis =0;
int LED_BAR =3;
int total =0;
// How many leds are in the strip?
#define NUM_LEDS 144
#define MAX_BRIGHTNESS 150 // watch the power!
// Data pin that led data will be written out over
#define DATA_PIN1 22
#define DATA_PIN2 52
int16_t position1 = 0; // Set initial start position of Red pixel
int16_t position2 = 1; // Set initial start position of White pixel
int16_t position3 = 2; // Set initial start position of Blue pixel
int8_t delta = 1; // Using a negative value will move pixels backwards.
uint16_t holdTime = 10; // Milliseconds to hold position before advancing
// This is an array of leds. One item for each led in your strip.
CRGB leds[NUM_LEDS];
}
void ledspeed() {
CurrentMillis =millis();
if (CurrentMillis - LastMillis >100) {
holdTime = loopspeed + 10;
LastMillis = CurrentMillis;
if (loopspeed > 100) {loopspeed =10;}
}
}
void setup() {
delay(2000);
FastLED.setBrightness(MAX_BRIGHTNESS);
FastLED.addLeds<WS2812B, DATA_PIN1, GRB>(leds, NUM_LEDS);
FastLED.addLeds<WS2812B, DATA_PIN2, GRB>(leds, NUM_LEDS);
Serial.begin(57600);
}
void loop() { // START MAIN LOOP
EVERY_N_MILLISECONDS(holdTime) {
// Set pixel color
leds[position1] = CRGB::White;
leds[position2] = CRGB::White;
leds[position3] = CRGB::White;
// Show the pixels
FastLED.show();
//delay(holdTime); // Delay for a bit.
// Set pixels back to Black for the next loop around.
leds[position1] = CRGB::Black;
leds[position2] = CRGB::Black;
leds[position3] = CRGB::Black;
// Set new position, moving (forward or backward) by delta.
// NUM_LEDS is added to the position before doing the modulo
// to cover cases where delta is a negative value.
position1 = (position1 + delta + NUM_LEDS) % NUM_LEDS;
position2 = (position2 + delta + NUM_LEDS) % NUM_LEDS;
position3 = (position3 + delta + NUM_LEDS) % NUM_LEDS;
// Print out position values to see what's happening.
//Serial.print("pos R = "); Serial.print(positionRed);
//Serial.print("\t pos W = "); Serial.print(positionWhite);
//Serial.print("\t pos B = "); Serial.println(positionBlue);
}
ledspeed();
} // END MAIN LOOP