LED bus driver on any GPIO pin for addressable RGB LEDs (like NeoPixels or other WS2812 based LEDs)
Diff: LEDBus.cpp
- Revision:
- 2:735bb1b9cfc2
- Parent:
- 1:6119419c2730
--- a/LEDBus.cpp Tue May 10 20:22:18 2016 +0000 +++ b/LEDBus.cpp Wed Jun 14 19:51:33 2017 +0000 @@ -1,9 +1,6 @@ #include "LEDBus.h" - - - -LEDBus::LEDBus(PinName wirePin, ByteOrder byteOrder, float t0h_us, float t0l_us, float t1h_us, float t1l_us, float tReset_us) : _wire(wirePin) +LEDBus::LEDBus(PinName wirePin, ColorByteOrder byteOrder, float t0h_us, float t0l_us, float t1h_us, float t1l_us, float tReset_us) : _wire(wirePin) { float ticksPerMicroSecond = SystemCoreClock/MICRO_SECOND; @@ -55,10 +52,11 @@ } } -void LEDBus::delay(unsigned int ticks) +void LEDBus::delay(unsigned const int ticks) { - // each loop should be around 6 clock cycles... - for (unsigned volatile int i = 0; i < ticks; i+=6) { + //loop_ticks is empirically determined (aka: works on my machine...) + const int loop_ticks = 8; + for (unsigned volatile int i = 0; i <= ticks-(loop_ticks/2); i+=loop_ticks) { /* nop */ } }