I have some code that fades across a strip of the led for a project but while creating the first version of my code which may seem slightly verbose and removing the FastLED.delay function to replace it with the millis version i was going to have the function return an integer that corresponds to the amount of time left until it fills the led strip up.
The code below is the class of what im using but for some weird reason everytime i add the return function it stops working entirely.
int Display::animate(int dir) {
unsigned long currentMillis = millis();
if (dir == 1 && currentMillis - _Display_Millis > _Display_Delay) { //Forwards Animation
leds[_Display_Position].setHSV(_Display_Current, 255, _Display_Fade_Position);
_Display_Fade_Position = constrain(_Display_Fade_Position + FadeIncrement, 0, Brightness);
if (_Display_Fade_Position >= Brightness) { //If we have brought the led to full brightness
_Display_Fade_Position = 0;
_Display_Position++;
}
if (_Display_Position == NUM_LEDS) { //If we are at the last led in the line
_Display_Fade_Position = 255;
_Display_Position = 17;
}
FastLED.show();
_Display_Millis = currentMillis;
} else {
leds[_Display_Position+1].setHSV(_Display_Colour, _Display_Saturation, Brightness);
_Display_Fade_Position = constrain(_Display_Fade_Position - FadeIncrement, 0, Brightness); //Dim the led
leds[_Display_Position].setHSV(_Display_Current, _Display_Current_Saturation, _Display_Fade_Position);
if (_Display_Fade_Position <= 0) {
_Display_Fade_Position = 255;
_Display_Position--;
}
if (_Display_Position <= 0) {
_Display_Fade_Position = 0;
_Display_Position = 0;
leds[_Display_Position].setHSV(_Display_Colour, _Display_Saturation, Brightness);
}
FastLED.delay(10);
FastLED.show();
}
}
Yes i am still using the FastLED.delay in the reverse side of things but as i said this is my work in progress and if i add a return 0; at the end of the function it no longer does anything to the led strip.
Any ideas on what i am doing wrong?