Profile cover photo
Profile photo
Paul Jaruszewski
21 followers -
H. sapien
H. sapien

21 followers
About
Posts

First code/idea contribution. Video is poor but will give the idea of what I am doing, code is functional but can easily be improved.

After seeing the LED VU meters and simulations of bouncing balls, fire, etc. I decided to make my own that incorporated a pushbutton switch. Easy to do even for someone who hasnt coded for dollars since 1985 thanks to the great numbers of people who generously share ideas and code.

So, my contribution is one I havent seen yet out here for people who are making these light shows. It is an indicator of what routine you are running. i.e. vu1, vu2, bouncing balls, fire1, fire2, etc. My display has no VU feature but does have a lot of routines I switch between with a momentary pushbutton. The code will interrupt the routine and display a number of LEDS that correspond to the routine number. THere is a two second timeout and a single press doesn't change the routine, only display the routine. The entire routine is below along with a link to the youtube video.


https://youtu.be/7fPUuIIgBcc


Paul

void checkButton() {
// read the pushbutton input pin:
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
buttonValueDisplayed = 1;
buttonDisplayTimer = millis();

for ( int k = 0; k < NUM_LEDS; k++) {
ledsTemp[k] = leds[k];
}
FastLED.clear();
digitalWrite(ledPin, HIGH);
int displayedButtonValue = 0; // First time through no value is displayed.
int i = 0; // LCV
int j = 0; // LCV
do { // Display button count for 2 seconds since last press.
while (displayedButtonValue != buttonValue) { // Prepare button display if not yet displayed.
FastLED.clear();
i = (NUM_LEDS - buttonValue) / 2;
for (j = 0; j < buttonValue; j++) {
if ((j + 1) % 5 == 0 ) {
leds[i] = CRGB ::Blue;
} else {
leds[i] = CRGB ::White;
}
i = i + 1;
}
FastLED.show();
displayedButtonValue = buttonValue;
delay(20);
}
buttonState = digitalRead(buttonPin);
while (buttonState == HIGH) { // Will sit here until button is released.
buttonState = digitalRead(buttonPin);
}
delay(20); // This is here because it may help with a bouncing contact.
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) { // If button is pressed again, increment button value and reset 2 second timer.
buttonValue = buttonValue + 1;
buttonValueChanged = 1; // flag that indicates the button value has changed.
if ( buttonValue > maxButtonValue ) {
buttonValue = 1;
}
buttonDisplayTimer = millis();
}
} while ((millis() - buttonDisplayTimer) < buttonDisplayDelay);
FastLED.clear();
for ( int k = 0; k < NUM_LEDS; k++) {
leds[k] = ledsTemp[k];
}
}
digitalWrite(ledPin, LOW);

}

I am sorry that I am not a more skilled programmer. My background is in 8080/Z80 machine code, APL, IDEA, BASIC, etc. from the late 70's / early 80's. So on to my question, which I think is more a FastLED question than a C++ question. I have a routine that halts my LED display, shows some info on the LED array then continues. What I want to do is restore the LED array to its former state after the routine runs. In other words duplicate the LED variable array. I can of course do a loop and copy each element into another array, then return the data back to the display array but that seems terribly inefficient. I am guessing that there is a fast LED function that can duplicate the data quickly as there are so many speed optimized routines within the fast LED library.

Any suggestions better than a for loop coming and going from the routine?

Thanks in advance. When I get the routine running to my satisfaction I will post a video demo as well as share the code.

Paul

Wait while more posts are being loaded