01 July 2021

Adafruit's Debounce CircuitPython Library

I think it was after whatever previous post that I had mentioned it, I decided to tinker with it some within the Powermate (I also was partially annoyed with the button's input behaviour that I programmed). After making the necessary changes (importing, assigning, etc.), I changed the if statements to look for rise or fall instead of the button value, and didn't have much luck getting it to work while tweaking the code. I ended up just undoing all of the changes and leaving the tinkering for another day.

Last Friday, I decided to give it another whirl (I think I was thinking about it the night before and figured something out that would probably make it work) and made the necessary changes once again. I don't remember exactly what I did, but I did use .rose and .fell in conjunction with .value to get it working. I also already had a counter implemented in the old code that counted the amount of cycles the button was being held for, and I had also changed it to accomodate the new sleep time of 10ms (since the debouncer class defaults to 10ms cycles). I found from the library documentation that there's also .current_duration and .last_duration and kinda played with those a bit, but .last_duration didn't seem to be that useful (or at least for me). I tried using .current_duration for the profile switching, but it ended up being problematic, so I changed it back to read from the counter system. I left .current_duration where it turns the LEDs to the colour of the current profile because it works fine and it doesn't matter if I use that or my counter system there. I also had tried .current_duration with what the button does when pressed, but didn't work well.

With the script for mine fixed up, I fixed the one for my friend and gave him the library and the new code, even if his button just toggles the LEDs on or off. Button definitely works a lot better than the old code, and definitely planning on using the debouncer library where possible.

No comments:

Post a Comment