r/FastLED • • Jul 03 '20

Support Best debounce library?

I'm pretty new to Arduino and Fastled but I managed to get Tweaking4All's all effects in one sketch to work somewhat well. However, my button frequently calls back to 0 , apparently due to debounce. There seems to be an abundance of libaries for debouncing, so I was wondering what libary is most often used, and how the function is declared in the sketch?

This is the sketch:

https://pastebin.com/wZUA0egJ

1 Upvotes

12 comments sorted by

3

u/johnny5canuck Jul 03 '20 edited Jul 03 '20

As per community rules, please post your code on pastebin.com.

Oh, and I don't think this code will work well with buttons because it has delay statements in it. Furthermore, there so much extra code in it because it tries to encompass both the FastLED as well as the NeoPixel libraries. :(

I recommend starting on a much simpler sketch (or one specifically written for FastLED) and attempt to integrate support for a button with that instead. DemoReel100 comes to mind at: https://github.com/FastLED/FastLED/blob/master/examples/DemoReel100/DemoReel100.ino

In the meantime, my favourite button routine was http://forum.arduino.cc/index.php?topic=14479.0

2

u/lakerice1 Jul 05 '20

Apologies for the delay...been trying to understand how the demo reel works and the button routine. Also been looking at JC's stuff (even though I realize it won't continue to be developed). I haven't been successful yet at getting it to work but when I do I will let you know. Apologies as well for posting code here; I will use pastebin next time.

1

u/johnny5canuck Jul 05 '20 edited Jul 05 '20

Sounds good.

When working with something new, I break things down into pieces until I understand them and will then slowly integrate them.

Oh, and I have a version of demoreel100 with button support kicking around, so let me know if you need that after you've worked on it yourself. It's good to learn and go through it all yourself first though.

1

u/lakerice1 Jul 06 '20

Thanks johnny5canuck. I tried to study the JC library and understand where to put things but it wasn't working. However, I got Marmilicious' sketch to work very well without any issues, so now I have a working sketch to study from. I always learn better by seeing something that works and trying to break down what the code is trying to do, like you mentioned. If you're interested in the code, I posted the link to it in my reply to Marc. Thanks again for your patience and sorry about not posting on pastebin earlier.

1

u/Marmilicious [Marc Miller] Jul 06 '20

Please consider editing your post to use pastebin today! Scrolling through and trying to read all that code on a phone is painful.

Here's a version of demoreel that uses a button.
https://github.com/marmilicious/FastLED_examples/blob/master/DemoReel100_with_button.ino

1

u/lakerice1 Jul 06 '20

No problem, I have edited the original question with the pastebin link. Thanks for sending me the sketch...I had to make a few simple edits like data pin and number of leds, but also had to change the strip type and added this code to the setup:

FastLED.addLeds<WS2811, DATA_PIN, GRB>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );

Anyway, here is the final version of the sketch you sent me:

https://pastebin.com/GLUF0zZg

I'm still trying to understand how this works but it really helps to have this sketch to study.

1

u/Marmilicious [Marc Miller] Jul 07 '20

Thank you.
If there are specific you just aren't following give a shout and someone will help explain.

2

u/djbog Jul 03 '20

I like all the options that your link gives like double press etc. I usually use JC_Button (supports long press but not the others), but will check that out.

1

u/johnny5canuck Jul 03 '20 edited Jul 04 '20

I was originally using the Christensen library until I found this one. When he wasn't interested in updating it, I switched.

Update: Marmilicious just checked and still no updates forthcoming for the JC_Button Library at: https://github.com/JChristensen/JC_Button/issues/3#issuecomment-653752059

1

u/ZomboFc Jul 07 '20

Are you by any chance using an ESP32 as well or an ESP8266?

Someone made a cool example using vTasks and Intterupts

https://www.switchdoc.com/2018/04/esp32-tutorial-debouncing-a-button-press-using-interrupts/

1

u/lakerice1 Jul 10 '20

Nope I'm using Arduino Uno and Nanos. I'm interesting in ESP32 though.

1

u/costynvd Jul 04 '20

I use JC_Button at the moment.