I had a need to test some displays that use the APA102 addressable LEDs. These have four wire connections, 5V, Clock, Data and Ground (0V).
The data format is one with a requirement where a start frame is sent, a number of 'LED' frames (to suit the number of LEDs in the display) followed by an end frame.
There are some confusing datasheets out on the 'net and it took me a while to get my head around the data formatting needed to illuminate the LEDs.
The program initially clears the display, sets all LEDs to Red, then Green, then Blue. It then lights each LED with a random colour before the pattern repeats, but more slowly, due to the RedDisplay(), GreenDisplay() and BlueDisplay() routines being called with their SlowD parameter set to 1 which incorporates longer delays between each LEDs data frame.
Not very exciting, but it did at least allow me to test the display matrixes I had, and prove which were working and which were not.
I couldn't find any programs for this display in BASIC so thought I'd post it in the hope that someone might be able to make use of it.
#OptionExplicit'Quick and dirty program for the APA102 addressable LED's with'5V, Clock, Data and Ground connections.'The data format is:'Start frame'32 bits at Low''Frame for each LED'3 bits at High.'5 bits of global brightness data'8 bits Blue data'8 bits Green data'8 bits Red data''End frame'32 bits at high'It was suggested that after 64 LED frames an 'End frame' should be sent'before sending the next LED frames.''I found that didn't seem to be required so send a set of 113 LED frames.''Although the LED array I had only 112 LEDs were fitted. I had to send 113'LED frames to ensure the final LED was correctly illuminated.'Without that last frame the final LED could be left fully lit?#Chip16F15313,32#ConfigCP=On'Read protected#DefineD_Clk1PortA.5'Pin 2#DefineD_DataPortA.4'Pin 3#DefineElements113DirD_Clk1OutDirD_DataOutDimRandDataAsByteLetD_Clk1=0ClearDisplay(0)RedDisplay(0)Wait500mSGreendDisplay(0)Wait500mSBlueDisplay(0)Wait500mSDoRandomDisplayRedDisplay(1)GreendDisplay(1)BlueDisplay(1)LoopSubRandomDisplay'Send Start FrameLetD_Data=0Repeat32ClockOutEndRepeatRepeatElements'Send Global frameLetD_Data=1ClockOutLetD_Data=1ClockOutLetD_Data=1ClockOut'Send brightness frameLetD_Data=0ClockOutLetD_Data=0ClockOutLetD_Data=0ClockOutLetD_Data=0ClockOutLetD_Data=1ClockOut'Send Blue frameLetRandData=RandomLetD_Data=RandData.0ClockOutLetD_Data=RandData.1ClockOutLetD_Data=RandData.2ClockOutLetD_Data=RandData.3ClockOutLetD_Data=RandData.4ClockOutLetD_Data=RandData.5ClockOutLetD_Data=RandData.6ClockOutLetD_Data=RandData.7ClockOut'Send Red frameLetRandData=RandomLetD_Data=RandData.0ClockOutLetD_Data=RandData.1ClockOutLetD_Data=RandData.2ClockOutLetD_Data=RandData.3ClockOutLetD_Data=RandData.4ClockOutLetD_Data=RandData.5ClockOutLetD_Data=RandData.6ClockOutLetD_Data=RandData.7ClockOut'Send Green frameLetRandData=RandomLetD_Data=RandData.0ClockOutLetD_Data=RandData.1ClockOutLetD_Data=RandData.2ClockOutLetD_Data=RandData.3ClockOutLetD_Data=RandData.4ClockOutLetD_Data=RandData.5ClockOutLetD_Data=RandData.6ClockOutLetD_Data=RandData.7ClockOutEndRepeat'Send End FrameLetD_Data=1Repeat32ClockOutEndRepeatLetD_Data=0EndSubSubClockOutLetD_Clk1=1Wait500uSLetD_Clk1=0Wait500uSEndSubSubKwikOutLetD_Clk1=1'Wait 1 uSLetD_Clk1=0'Wait 1 uSEndSubSubClearDisplay(SlowDAsByte)IfSlowD=0Then'Send Start FrameLetD_Data=0Repeat32KwikOutEndRepeatRepeatElementsLetD_Data=1Repeat3KwikOutEndRepeatLetD_Data=0'five brightness bitsRepeat5KwikOutEndRepeat'24 RGB bits (8 x Red, 8 x Green, 8 x Blue)Repeat24KwikOutEndRepeatEndRepeat'Send End FrameLetD_Data=1Repeat32KwikOutEndRepeatLetD_Data=0Else'Send Start FrameLetD_Data=0Repeat32ClockOutEndRepeatRepeatElementsLetD_Data=1Repeat3ClockOutEndRepeatLetD_Data=0'five brightness bitsRepeat5ClockOutEndRepeat'24 RGB bits (8 x Red, 8 x Green, 8 x Blue)Repeat24ClockOutEndRepeatEndRepeat'Send End FrameLetD_Data=1Repeat32ClockOutEndRepeatLetD_Data=0EndIfEndSubSubRedDisplay(SlowDAsByte)IfSlowD=0Then'Send Start FrameLetD_Data=0Repeat32KwikOutEndRepeatRepeatElementsLetD_Data=1Repeat3KwikOutEndRepeatLetD_Data=0'Four brightness bits of zeroRepeat4KwikOutEndRepeat'One brightness bit of oneLetD_Data=1KwikOut'24 RGB bits (8 x Blue, 8 x Green, 8 x RedLetD_Data=0Repeat8KwikOutEndRepeatLetD_Data=0Repeat8KwikOutEndRepeatLetD_Data=1Repeat8KwikOutEndRepeatEndRepeat'Send End FrameLetD_Data=1Repeat32KwikOutEndRepeatLetD_Data=0Else'Send Start FrameLetD_Data=0Repeat32ClockOutEndRepeatRepeatElementsLetD_Data=1Repeat3ClockOutEndRepeatLetD_Data=0'Four brightness bits of zeroRepeat4ClockOutEndRepeat'One brightness bit of oneLetD_Data=1ClockOut'24 RGB bits (8 x Blue, 8 x Green, 8 x RedLetD_Data=0Repeat8ClockOutEndRepeatLetD_Data=0Repeat8ClockOutEndRepeatLetD_Data=1Repeat8ClockOutEndRepeatEndRepeat'Send End FrameLetD_Data=1Repeat32ClockOutEndRepeatLetD_Data=0EndIfEndSubSubGreendDisplay(InSlowDAsByte)IfSlowD=0Then'Send Start FrameLetD_Data=0Repeat32KwikOutEndRepeatRepeatElementsLetD_Data=1Repeat3KwikOutEndRepeatLetD_Data=0'Four brightness bits of zeroRepeat4KwikOutEndRepeat'One brightness bit of oneLetD_Data=1KwikOut'24 RGB bits (8 x Blue, 8 x Green, 8 x RedLetD_Data=0Repeat8KwikOutEndRepeatLetD_Data=1Repeat8KwikOutEndRepeatLetD_Data=0Repeat8KwikOutEndRepeatEndRepeat'Send End FrameLetD_Data=1Repeat32KwikOutEndRepeatLetD_Data=0Else'Send Start FrameLetD_Data=0Repeat32ClockOutEndRepeatRepeatElementsLetD_Data=1Repeat3ClockOutEndRepeatLetD_Data=0'Four brightness bits of zeroRepeat4ClockOutEndRepeat'One brightness bit of oneLetD_Data=1ClockOut'24 RGB bits (8 x Blue, 8 x Green, 8 x RedLetD_Data=0Repeat8ClockOutEndRepeatLetD_Data=1Repeat8ClockOutEndRepeatLetD_Data=0Repeat8ClockOutEndRepeatEndRepeat'Send End FrameLetD_Data=1Repeat32ClockOutEndRepeatLetD_Data=0EndIfEndSubSubBlueDisplay(SlowDAsByte)IfSlowD=0Then'Send Start FrameLetD_Data=0Repeat32KwikOutEndRepeatRepeatElementsLetD_Data=1Repeat3KwikOutEndRepeatLetD_Data=0'Four brightness bits of zeroRepeat4KwikOutEndRepeat'One brightness bit of oneLetD_Data=1KwikOut'24 RGB bits (8 x Blue, 8 x Green, 8 x RedLetD_Data=1Repeat8KwikOutEndRepeatLetD_Data=0Repeat8KwikOutEndRepeatLetD_Data=0Repeat8KwikOutEndRepeatEndRepeat'Send End FrameLetD_Data=1Repeat32KwikOutEndRepeatLetD_Data=0Else'Send Start FrameLetD_Data=0Repeat32ClockOutEndRepeatRepeatElementsLetD_Data=1Repeat3ClockOutEndRepeatLetD_Data=0'Four brightness bits of zeroRepeat4ClockOutEndRepeat'One brightness bit of oneLetD_Data=1ClockOut'24 RGB bits (8 x Blue, 8 x Green, 8 x RedLetD_Data=1Repeat8ClockOutEndRepeatLetD_Data=0Repeat8ClockOutEndRepeatLetD_Data=0Repeat8ClockOutEndRepeatEndRepeat'Send End FrameLetD_Data=1Repeat32ClockOutEndRepeatEndIfEndSub
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
It is a string of LEDs arranged by the Chinese manufacturer of some of the machines we import into a 4 x seven segment LED display. The manufacturer also uses the same devices in "strings" for lighting the cabinets.
The part number is APA102, though the ones installed in the displays I have could be "clones".
I should add that in the program above the global brightness is set to 1 by setting the first four bits of the brightness frame to 0, then the final bit of the brightness frame set to 1.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I had a need to test some displays that use the APA102 addressable LEDs. These have four wire connections, 5V, Clock, Data and Ground (0V).
The data format is one with a requirement where a start frame is sent, a number of 'LED' frames (to suit the number of LEDs in the display) followed by an end frame.
There are some confusing datasheets out on the 'net and it took me a while to get my head around the data formatting needed to illuminate the LEDs.
The program initially clears the display, sets all LEDs to Red, then Green, then Blue. It then lights each LED with a random colour before the pattern repeats, but more slowly, due to the RedDisplay(), GreenDisplay() and BlueDisplay() routines being called with their SlowD parameter set to 1 which incorporates longer delays between each LEDs data frame.
Not very exciting, but it did at least allow me to test the display matrixes I had, and prove which were working and which were not.
I couldn't find any programs for this display in BASIC so thought I'd post it in the hope that someone might be able to make use of it.
Cool.
Which part/display was this?
It is a string of LEDs arranged by the Chinese manufacturer of some of the machines we import into a 4 x seven segment LED display. The manufacturer also uses the same devices in "strings" for lighting the cabinets.
The part number is APA102, though the ones installed in the displays I have could be "clones".
I should add that in the program above the global brightness is set to 1 by setting the first four bits of the brightness frame to 0, then the final bit of the brightness frame set to 1.