View Single Post
  #14  
Old 12-23-2019, 09:35 AM
Wombii's Avatar
Wombii Wombii is offline
Green Horn
 
Join Date: Feb 2018
Location: Norway
Posts: 231
Wombii is on a distinguished road
Default Re: Remote LED switching with Arduino examples.

Sorry, I didn't see your last post until today.
That's a great project to work with the arduino. Seemingly simple on the surface, but can be made terribly complex as you work to perfect each function.

Post #4 above contains an example that could be used to switch turn signals or work lights by flicking the steering a number of times left or right.

I'd say that unless you run into timing critical things that absolutely can not hang or crash, and are reading 3 channels or less, just go with pulseIn. For a lightkit you probably don't need to do stuff anyway without having got an update on the RC channel data.
You just need to be aware that the pulseIn way may in the worst case scenario need 2 frame times (5/11/16.5/20 ms) to read each channel depending on the order the receiver outputs them. If your receiver updates each channel every 20ms, you might for example read throttle pulse, miss steering pulse, wait 20ms for the next steering pulse, then the same for channel 3, meaning your arduino program only loops every 60ms instead of 20. If this gives you an issue, I have made a bit of code that always reads 3 channels in one cycle but sacrifices a bit of accuracy. Another option is to only read one channel in each loop.
If you want to read more than 3 channels with pulseIn or the looptimes end up longer than your light flashing intervals, you can probably work around most issues by changing the order you're reading the channels in. (One of my receivers output ch1 and ch2 at the same time before ch3, so reading ch1-ch3-ch2 instead of ch1-ch2-ch3 saved me 20 ms).

For my fire truck project I'm using the SBUS protocol to read 16 channels.

You may want to have a look at Open Source Lights, an arduino based light controller. I don't use it personally as I started my project long before I found it, but it's very good (though complex to read through because of all the configuration options). I tried to help by contributing my light flashing+fading code in version 3, but some people have had problems with it, so you might want to look at version 2. It uses pulseIn, but with some error checking. V3 reads only one channel per loop to make sure it gets a stable loop time, because it uses loop counts instead of millis() to flash the lights.
Reply With Quote