Hi all,
Could anyone please tell me why in the code below void Fastled I am getting 5 leds scrolling (which I want) but in the void Fast I am getting only one led scrolling.
Thank you all in advance.Any help gratefuly received.
[/#include <FastLED.h>
#include <OneWire.h>
#include <DallasTemperature.h>
// Define the array of leds
#define LED_DT 6
#define COLOR_ORDER GRB
#define LED_TYPE WS2812
#define NUM_LEDS 150
uint8_t max_bright = 255;
struct CRGB leds[NUM_LEDS];
#define ONE_WIRE_BUS 2
int index1;
int index2;
int index3;
unsigned long initialtime;
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
void setup() {
delay (500);
LEDS.addLeds<LED_TYPE, LED_DT, COLOR_ORDER>(leds, NUM_LEDS);
FastLED.setBrightness(max_bright);
index1 = 0;
index2 = 0;
index3 = 0;
initialtime = millis();
//Serial.begin(9600);
//Serial.println("Dallas Temperature IC Control Library Demo");
sensors.setResolution(9);
sensors.begin();
}
void loop() {
sensors.requestTemperatures();
//Serial.print(sensors.getTempCByIndex(0));
if (sensors.getTempCByIndex(0) >= 24) {
FASTLED();
}
if (sensors.getTempCByIndex(1) >= 24) {
FAST();
}
}
// Repeat this with fast
void FASTLED() {
for(int a =0;a<=150; a++){ // ~105-110s use a-- to reverse and a=150
FastLED.clear();
set5leds(index1);
index1 = (index1 + 1) % (NUM_LEDS - 4);
if (millis() - initialtime > 1000) {
}
set5leds(index2);
index2 = (index2 + 1) % (NUM_LEDS - 4);
if (millis() - initialtime > 2000) {
set5leds(index3);
index3 = (index3 + 1) % (NUM_LEDS - 4);
if (millis() - initialtime > 3000) {
}
FastLED.show();
delay (0);
}
}
}
void set5leds(int pos) {
leds[pos].setRGB (0, 255, 0);
leds[pos + 1].setRGB (0, 255, 0);
leds[pos + 2].setRGB (0, 255, 0);
leds[pos + 3].setRGB (0, 255, 0);
leds[pos + 4].setRGB (0, 255, 0);
}
//Reverse
void FAST() {
for(int a =150;a>=10; a--){
FastLED.clear();
set5leds2(index1);
index1 = (index1 + 1) % (NUM_LEDS + 4);
if (millis() - initialtime > 1000) {
}
set5leds2(index2);
index2 = (index2 + 1) % (NUM_LEDS + 4);
if (millis() - initialtime > 2000) {
set5leds2(index3);
index3 = (index3 + 1) % (NUM_LEDS + 4);
if (millis() - initialtime > 3000) {
}
FastLED.show();
delay (0);
}
}
}
void set5leds2(int pos) {
pos = (NUM_LEDS-pos-1);
leds[constrain(pos,0, NUM_LEDS)].setRGB (0, 255, 0);
leds[constrain(pos,0, NUM_LEDS-1)].setRGB (0, 255, 0);
leds[constrain(pos,0, NUM_LEDS-2)].setRGB (0, 255, 0);
leds[constrain(pos,0, NUM_LEDS-3)].setRGB (0, 255, 0);
leds[constrain(pos,0, NUM_LEDS-4)].setRGB (0, 255, 0);
}
code]