How to fade led w/ sin while also reading from sensor?
Program it as a state machine with all non-blocking code:
Do Transition LED If a reading is ready, read If a new reading is needed, start new reading LoopMore on reddit.com
Dynamically timed actions
Hey all, I have an Arduino nano, an LED strip, and a VL53L1X TOF sensor. In an ideal world, while the LED strip is fading in and out via sin function, I would read the values from the sensor and update the LEDs accordingly. I have tried to implement this, but the LED isnt transitioning smoothly but rather in large steps.
I am 99% sure I know why this is. I believe it is due to the fact that I set the VL53L1X to have a timing budget of 200ms and a wait period of 200ms in an effort to reduce some reading issues I was having. So all in all, the sensor read takes roughly 400ms. Because arduino is single core, the fading of the led strip is put on hold during each successive sensor read, thus, instead of getting a clean sin fade, i am getting more of a "stair-step" fade effect.
In a perfect world, I would just dig around the drunk drawer for another core to use but unfortunately that aint how it works, so do you guys/gals have any insight into how I might be able to get around this?
Right now I fully expect that their isnt.
I am using the Pololou VL53L1X.h library with Wire.h
Program it as a state machine with all non-blocking code:
Do
Transition LED
If a reading is ready, read
If a new reading is needed, start new reading
Loop
I am sure. I had the LED sin fade working properly without the sensor reading implemented. Initially after implementing the sensor into the setup my sensor timing was set to 50ms and wait time was 0. The stepping did also occur then but it was a much smaller step, and while noticeable wasnt egregous enough to be an issue.