Démonstration du module LedRgb avec un contrôleur TLC59116.
Ce programme allume successivement 4 leds RGB connectées à un TLC59116 avec les couleurs de l'arc-en-ciel, puis il modifie la luminosité des leds pour chaque couleur et enfin effectue un test de la fonction clignotement couleur par couleur.
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <signal.h>
#include <sysio/delay.h>
#include <sysio/ledrgb.h>
#define NOF_LEDS 4
static void
vSigIntHandler (int sig) {
int ret;
if (ret != 0) {
printf ("\niLedRgbDeleteDevice() failed with %d returned value\n", ret);
exit (EXIT_FAILURE);
}
printf ("\neverything was closed.\nHave a nice day !\n");
exit (EXIT_SUCCESS);
}
int
main (int argc, char **argv) {
int ret;
uint32_t color_code[7] = {RGB_PURPLE, RGB_INDIGO, RGB_BLUE, RGB_GREEN, RGB_YELLOW, RGB_ORANGE, RGB_RED};
char * color_name[7] = { "violet", "indigo", "bleu", "vert", "jaune", "orange", "rouge" };
{.
i2c_bus =
"/dev/i2c-1", .i2c_addr =
TLC59116_ADDR (0, 0, 0, 0) },
{.i2c_bus = NULL, 0}
};
{
.
red = { .
out = 0, .ctrl = 0 },
.green = { .out = 1, .ctrl = 0 },
.blue = { .out = 2, .ctrl = 0 }
},
{
.red = { .out = 9, .ctrl = 0 },
.green = { .out = 10, .ctrl = 0 },
.blue = { .out = 11, .ctrl = 0 }
},
{
.red = { .out = 3, .ctrl = 0 },
.green = { .out = 4, .ctrl = 0 },
.blue = { .out = 5, .ctrl = 0 }
},
{
.red = { .out = 6, .ctrl = 0 },
.green = { .out = 7, .ctrl = 0 },
.blue = { .out = 8, .ctrl = 0 }
}
};
if (dev == NULL) {
printf ("Error: Unable to connect to TLC59116 controllers, check their configuration or hardware !\n");
exit (EXIT_FAILURE);
}
for (int i = 0; i < NOF_LEDS; i++) {
if (ret < 0) {
printf ("Error:Unable to add led number %d !\n", i);
exit (EXIT_FAILURE);
}
}
signal (SIGINT, vSigIntHandler);
printf ("TLC59116 Led RGB Demo\nPress Ctrl+C to abort ...\n");
for (;;) {
for (int color = 0; color < 7; color++) {
printf ("%s: ", color_name [color]);
if (ret != 0) {
printf ("Error:Unable to set color for led %d !\n", led);
exit (EXIT_FAILURE);
}
putchar ('.');
fflush (stdout);
}
putchar ('\n');
}
for (int color = 0; color < 7; color++) {
if (ret != 0) {
printf ("Error:Unable to dimmer for all leds !\n");
exit (EXIT_FAILURE);
}
printf ("%s\n", color_name [color]);
if (ret != 0) {
printf ("Error:Unable to set color all leds !\n");
exit (EXIT_FAILURE);
}
for (int dim = 0; dim <= 255; dim++) {
if (ret != 0) {
printf ("Error:Unable to dimmer for all leds !\n");
exit (EXIT_FAILURE);
}
}
}
for (int color = 0; color < 7; color++) {
printf ("%s\n", color_name [color]);
if (ret != 0) {
printf ("Error:Unable to set color all leds !\n");
exit (EXIT_FAILURE);
}
if (ret != 0) {
printf ("Error:Unable to dimmer for all leds !\n");
exit (EXIT_FAILURE);
}
if (ret != 0) {
printf ("Error:Unable to blinker for all leds !\n");
exit (EXIT_FAILURE);
}
if (ret != 0) {
printf ("Error:Unable to dimmer for all leds !\n");
exit (EXIT_FAILURE);
}
}
if (ret != 0) {
printf ("Error:Unable to dimmer for all leds !\n");
exit (EXIT_FAILURE);
}
}
return 0;
}