APA102 shift LED example

For general Flowcode discussion that does not belong in the other sections.
Post Reply
RGV250
Posts: 264
http://meble-kuchenne.info.pl
Joined: Sat Mar 19, 2022 4:53 pm
Has thanked: 23 times
Been thanked: 30 times

APA102 shift LED example

Post by RGV250 »

Hi,
I have bought a christmas tree from https://thepihut.com/products/3d-rgb-xm ... spberry-pi The demo code does not seem to be very adaptable so I thought I would give FC a go. I have downloaded the APA102 example and stripped out what I do not need and am working through some options.
I can get them all to turn on and off and set individual ones etc but I cannot get the shift LED macro to work and wondered if I am looking at it correctly.
I have tried pretty much all the options and wondered if there is a parameter or 2 missing. There are 2 parameters, direction and mode but whatever I do I only get the first LED to light. I wondered if there should be a parameter for the number of shifts as there is an index variable and a delay between shifts or they may just go too fast. I did wonder if I should put it in a loop but then what is the point of the macro in the example.
Pi_Hut_Tree_2.fcfx
(56.96 KiB) Downloaded 79 times
Bob

medelec35
Matrix Staff
Posts: 1451
Joined: Wed Dec 02, 2020 11:07 pm
Has thanked: 512 times
Been thanked: 472 times

Re: APA102 shift LED example

Post by medelec35 »

Hi Bob.
You are using the APA102C component source, which is not intended to be used for compiling to embedded devices.
To get full use of simulation, you should be using the component itself.
APA102C.png
APA102C.png (10.15 KiB) Viewed 2244 times
I Would recommend starting again but using the actual component.
Then get the simulation working first, then send to the RPI.
Martin

BenR
Matrix Staff
Posts: 1739
Joined: Mon Dec 07, 2020 10:06 am
Has thanked: 440 times
Been thanked: 603 times

Re: APA102 shift LED example

Post by BenR »

Hi Bob,

It looks like you have started with the component source project. Thats probably ok but there's probably a lot in there that you won't be needing for you're embedded project. Also you don't get the simulation. Aha I see Martin beat me to it here.

I've modified your project so it's now using the APA102 component rather then the source code so you can simulate the LEDs.

Anyway regarding the shift problem. I've also made some changes for you here. I've created an array for the RGB colour and an array for the count direction. Each colour channel will count up and down independently using a random mask to allow for some variation between channels. This colour is assigned to LED 0 and then shifted along so you get a nice shifting colour across the LEDs.
Pi_Hut_Tree_2.fcfx
(16.32 KiB) Downloaded 67 times

BenR
Matrix Staff
Posts: 1739
Joined: Mon Dec 07, 2020 10:06 am
Has thanked: 440 times
Been thanked: 603 times

Re: APA102 shift LED example

Post by BenR »

Another example here with bigger increments between colours so you can better see the colour changing across the 25 leds.

APA102_Demo.fcfx
(17.83 KiB) Downloaded 128 times
I've also put this as an example on the APA102C component wiki page.
https://www.flowcode.co.uk/wiki/index.p ... 02C_(LEDs)

RGV250
Posts: 264
Joined: Sat Mar 19, 2022 4:53 pm
Has thanked: 23 times
Been thanked: 30 times

Re: APA102 shift LED example

Post by RGV250 »

Hi,
Thanks for the replies and the example. I did search for an example which is what I thought was what I had downloaded. I sort of thought it just demo'd everything possible so deleted what I thought I would not need. As for starting off with just the actual component, it is OK if you know what you are doing but I doubt I would have got as far as I had.
The example is working fine so now I am going to play with it to get a wider colour change. I do not know if it is the type of LED or just something to do with random but they all seem to be white to faint blue and not a lot of red or green. I may try with one colour off and swapping to a different one every so often.

Regards,
Bob

BenR
Matrix Staff
Posts: 1739
Joined: Mon Dec 07, 2020 10:06 am
Has thanked: 440 times
Been thanked: 603 times

Re: APA102 shift LED example

Post by BenR »

Hi Bob,

Could be the LEDs are saturating well below the 255 max colour brightness. You could try changing the upper colour limit to say 64 or 128 and then adjusting the step so that it can't be as big.

Maybe try this and see if this works any better, i've limited things to 64. The sim will now be pretty dark but the actual LEDs should still be nice and bright and use a quarter of the current of the previous version.
APA102_Demo2.fcfx
(17.83 KiB) Downloaded 73 times
you could also maybe try dividing the blue channel by 2 when writing to LED 0 and see if that helps to tame things. There is normally one channel that isn't fully balanced with the others with these smart LEDs.

RGV250
Posts: 264
Joined: Sat Mar 19, 2022 4:53 pm
Has thanked: 23 times
Been thanked: 30 times

Re: APA102 shift LED example

Post by RGV250 »

Hi Ben,
Thanks, quite a bit better now. It works much better than the (Pi hut) demo code. Lots of different effects to play with now over the weekend.

I may have to dig out the strips of LED's I have had for ages and get even more chistmassy now.

Bob

Post Reply