pnaven03
Posts: 131
Joined: Thu Feb 16, 2017 5:21 pm

Re: How to control SK6812 LED's using C source code

Fri Sep 28, 2018 2:40 pm

Thanks for the reply,

This will work individual LED's operation or only rows and columns ?

This LED's continuous ON/OFF single LED's,Rows etc and changing to different colors in while loop this will work ?

danjperron
Posts: 3073
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: How to control SK6812 LED's using C source code

Fri Sep 28, 2018 5:28 pm

This will work individual LED's operation or only rows and columns ?
I don't understand your question.

Each of my new fonctions, matrix_setXXX(), modify the contents of the matrix without actually do something on the led.
The new matrix_render() do the actually transfer to the leds data.
This LED's continuous ON/OFF single LED's,Rows etc and changing to different colors in while loop this will work ?
Even that one I don't understand what you mean.

The example in main.c should display a full red, a moving row and a moving column with an interval of 1 second continuously.

Does it works?

pnaven03
Posts: 131
Joined: Thu Feb 16, 2017 5:21 pm

Re: How to control SK6812 LED's using C source code

Mon Oct 01, 2018 9:45 am

Thanks for the reply,

Source code working for complete rows,columns. My another requirement is to turn ON and OFF randomly with individual LED's (2,4,8,10 etc).
If i need to trurn ON third led after some times agian turn off, this led turn ON and OFF not depends on time.
What is the exact code to turn ON my third LED, added source code is to correct ?

matrix_setLed(3,0,30,0,0);
matrix_render();
mysleep(1.0);

In source code after main added above two lines and commented while loop, compiled and run exe file in command prompt.
observed turn ON and after one seconds change to OFF state, In my original source code not running while loop without while led not operate ?

Suppose normal GPIO led operation when led turn OFF and ON individual LED's by using below command
echo 1 > /sys/clss/gpio/gpio15/value //ON
echo 0 > /sys/clss/gpio/gpio15/value //OFF

Please provide me any solution for this.

danjperron
Posts: 3073
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: How to control SK6812 LED's using C source code

Mon Oct 01, 2018 10:47 am

Suppose normal GPIO led operation when led turn OFF and ON individual LED's by using below command
echo 1 > /sys/clss/gpio/gpio15/value //ON
echo 0 > /sys/clss/gpio/gpio15/value //OFF
Wow you mixed neopixel system with normal gpio action. Are you sure that you understand what you are doing?


matrix_setLed() set specific led from row to column from OFF (,,0,0,0) to ON on any color and intensity. So for my point of view you question about ON/OFF is very weird.

OFF is to set R,G and B to 0 on matrix_setLed()
ON is to set them to any other number. The led will turn ON.


For a random third led use the rand() function


example of a rsandom number with a seed generator

Code: Select all

#include <stdlib.h>
#include <time.h>
#include <stdio.h>



int main(void)
{
  struct timespec spec;
  clock_gettime(CLOCK_REALTIME, &spec);

  srand(spec.tv_nsec);
  printf("%d\n",rand() % 256);
  return 0;
}


Create yourself a function to generate a random color

maxLed=32; // define max led intensity
#define RND (srand() % maxLed)
matrix_setLed(3,row, RND,RND,RND);

For timing in random, usedelay in millisecond and check for a constant ncount for normal operation but in the loop create a random to generate your third led.

This is really not complicated! You should be able to do it alone.

pnaven03
Posts: 131
Joined: Thu Feb 16, 2017 5:21 pm

Re: How to control SK6812 LED's using C source code

Mon Oct 01, 2018 11:17 am

Yes i know GPIO and Neopixel total different concepts.

Suppose I am trying to turn ON second LED by using your code, change to ON state but immediately going to off state. when turn ON it should be ON state and when change to OFF state should be going to off state.

Added below code is it coorect ?


int main(int argc, char *argv[])
{
ws2811_return_t ret;

matrix = malloc(sizeof(ws2811_led_t) * width * height);

if ((ret = ws2811_init(&ledstring)) != WS2811_SUCCESS)
{
fprintf(stderr, "ws2811_init failed: %s\n", ws2811_get_return_t_str(ret));
return ret;
}

matrix_setLed(1,0,30,0,0); //Turn ON second led
matrix_render();
mysleep(1.0);

}

When am trying to turn ON only single second LED reaming all in off state, when i run above code going to ON state second led and immediately going to OFF state. any mistakes in code ?

complete rows and columns working perfectly your code without any issues.

danjperron
Posts: 3073
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: How to control SK6812 LED's using C source code

Mon Oct 01, 2018 11:47 am

You are exiting the program! you are not in a loop.

First thing the program will do is to clear all led and then do your one led on and quit!

I know that my code by default turn off everything when it quit!. the ctrl-c handler routine

How does your code clean the mess when you quit. I don't see any clean up code there!
Whereis ws2811_fini(&ledstring)?

if you want to do code that quit all the time you need to thing about holding last values of you led information. Use a file to store the information.
You will need to take care how you quit. Close the SPI and be sure that the GPIO stay on the same state.

B.T.W. On my code if you set clear_on_exit to zero, the led stay the same when you quit!

pnaven03
Posts: 131
Joined: Thu Feb 16, 2017 5:21 pm

Re: How to control SK6812 LED's using C source code

Mon Oct 01, 2018 12:11 pm

Many thanks for continuous help,

after clear_on_exit value change zero issues resolved, I am trying to turn on single led without while loop in latest source code.

danjperron
Posts: 3073
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: How to control SK6812 LED's using C source code

Mon Oct 01, 2018 1:48 pm

If you want to change a single led without affecting others leds you will need to save the matrix into a file.

Your program will have to do

- Load matrix info from a file.
- Set your new leds.
- Save matrix info to file.

Return to “C/C++”