Gestion des LED avec clignottement et pulsation
This commit is contained in:
parent
0b1fcaa085
commit
d2552f198b
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@ -15,6 +15,7 @@
|
||||
"rp2040_sdio.h": "c",
|
||||
"util.h": "c",
|
||||
"stddef.h": "c",
|
||||
"log_usb.h": "c"
|
||||
"log_usb.h": "c",
|
||||
"ws2812.h": "c"
|
||||
}
|
||||
}
|
||||
77
main.c
77
main.c
@ -134,6 +134,7 @@ void sd_card_gestion(){
|
||||
|
||||
void core1_functions(){
|
||||
while(1){
|
||||
ws2812_gestion();
|
||||
ws2812_affiche_buffer();
|
||||
sleep_ms(2);
|
||||
}
|
||||
@ -142,6 +143,10 @@ void core1_functions(){
|
||||
|
||||
/*------------- MAIN -------------*/
|
||||
int main(void) {
|
||||
gpio_set_function(12, UART_FUNCSEL_NUM(uart0, 12));
|
||||
gpio_set_function(13, UART_FUNCSEL_NUM(uart0, 13));
|
||||
printf("TinyUSB Host CDC MSC HID - Logs\r\n");
|
||||
|
||||
multicore_launch_core1(core1_functions);
|
||||
board_init();
|
||||
ws2812_init();
|
||||
@ -154,15 +159,75 @@ int main(void) {
|
||||
gpio_set_dir(1, GPIO_IN);
|
||||
gpio_pull_up(1);
|
||||
|
||||
/*while(1){
|
||||
sd_card_gestion();
|
||||
float f;
|
||||
absolute_time_t current_time, start_time;
|
||||
start_time = get_absolute_time() / 1000.;
|
||||
|
||||
}*/
|
||||
uint32_t couleur[13];
|
||||
|
||||
couleur[0]=0x000800;
|
||||
couleur[1]=0x040800;
|
||||
couleur[2]=0x080800;
|
||||
couleur[3]=0x080400;
|
||||
couleur[4]=0x080000;
|
||||
couleur[5]=0x080004;
|
||||
couleur[6]=0x080008;
|
||||
couleur[7]=0x040008;
|
||||
couleur[8]=0x000008;
|
||||
couleur[9]=0x000408;
|
||||
couleur[10]=0x000808;
|
||||
couleur[11]=0x000804;
|
||||
couleur[12]=0x000800;
|
||||
uint8_t index_couleur=0;
|
||||
|
||||
ws2812_set_mode(LED_ID_SD_CARD, LED_CLI_RAPIDE, 0x000004);
|
||||
ws2812_set_mode(LED_ID_USB, LED_CLI_NORMAL, 0x000004);
|
||||
ws2812_set_mode(LED_ID_ASSERV, LED_CLI_PANIQUE_1, 0x000004);
|
||||
ws2812_set_mode(LED_ID_DETECTION, LED_PULSE_RAPIDE, 0x000004);
|
||||
|
||||
|
||||
while(1){
|
||||
f = get_absolute_time() / 1000. - start_time;
|
||||
f = f / 1000.;
|
||||
if(f > 1){
|
||||
f=1;
|
||||
start_time = get_absolute_time() / 1000.;
|
||||
f = 0;
|
||||
index_couleur++;
|
||||
if(index_couleur > 11){
|
||||
index_couleur = 0;
|
||||
}
|
||||
}
|
||||
//ws2812_set_buffer(ws2812_mix_color(couleur[index_couleur], couleur[index_couleur+1],f), 4);
|
||||
ws2812_set_mode(LED_ID_SD_CARD, LED_CLI_RAPIDE, 0x000004);
|
||||
ws2812_set_mode(LED_ID_USB, LED_CLI_NORMAL, 0x000004);
|
||||
ws2812_set_mode(LED_ID_ASSERV, LED_CLI_PANIQUE_1, 0x000004);
|
||||
ws2812_set_mode(LED_ID_DETECTION, LED_PULSE_RAPIDE, 0x000004);
|
||||
ws2812_set_mode(LED_ID_DIVERS, LED_STABLE, 0x000004);
|
||||
|
||||
sleep_ms(3000);
|
||||
|
||||
ws2812_set_mode(LED_ID_SD_CARD, LED_CLI_RAPIDE, 0x000404);
|
||||
ws2812_set_mode(LED_ID_USB, LED_CLI_NORMAL, 0x000404);
|
||||
ws2812_set_mode(LED_ID_ASSERV, LED_CLI_LENT, 0x000404);
|
||||
ws2812_set_mode(LED_ID_DETECTION, LED_CLI_PANIQUE_1, 0x000404);
|
||||
ws2812_set_mode(LED_ID_DIVERS, LED_CLI_PANIQUE_2, 0x000404);
|
||||
|
||||
sleep_ms(3000);
|
||||
|
||||
ws2812_set_mode(LED_ID_SD_CARD, LED_CLI_PANIQUE_3, 0x040000);
|
||||
ws2812_set_mode(LED_ID_USB, LED_PULSE_RAPIDE, 0x040000);
|
||||
ws2812_set_mode(LED_ID_ASSERV, LED_PULSE_NORMAL, 0x040000);
|
||||
ws2812_set_mode(LED_ID_DETECTION, LED_PULSE_LENT, 0x040000);
|
||||
ws2812_set_mode(LED_ID_DIVERS, LED_STABLE, 0x040000);
|
||||
|
||||
sleep_ms(3000);
|
||||
|
||||
sleep_ms(1);
|
||||
|
||||
}
|
||||
|
||||
|
||||
gpio_set_function(12, UART_FUNCSEL_NUM(uart0, 12));
|
||||
gpio_set_function(13, UART_FUNCSEL_NUM(uart0, 13));
|
||||
printf("TinyUSB Host CDC MSC HID - Logs\r\n");
|
||||
|
||||
// init host stack on configured roothub port
|
||||
// à mettre avant tuh_init
|
||||
|
||||
151
ws2812.c
151
ws2812.c
@ -3,14 +3,24 @@
|
||||
#include "ws2812.h"
|
||||
#include "ws2812.pio.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#define WS2812_PIN 15
|
||||
#define IS_RGBW false
|
||||
#define NB_WS2812 5
|
||||
|
||||
|
||||
uint32_t couleur[13];
|
||||
uint32_t buffer_couleur[12];
|
||||
|
||||
struct ws2812_type_gestion_t
|
||||
{
|
||||
enum led_type_gestion_t led_type_gestion;
|
||||
uint32_t couleur;
|
||||
} ws2812_type_gestion[NB_WS2812];
|
||||
|
||||
void ws2812_set_buffer(uint32_t couleur, uint8_t index_led);
|
||||
static inline uint32_t urgb_u32(uint8_t r, uint8_t g, uint8_t b);
|
||||
|
||||
void ws2812_init(){
|
||||
couleur[0]=0x000200;
|
||||
@ -65,6 +75,8 @@ void ws2812_init(){
|
||||
// Tout rouge !
|
||||
for(uint32_t i = 0; i<12; i++){
|
||||
ws2812_set_buffer_rgb(ORANGE_24BITS, i);
|
||||
ws2812_type_gestion[NB_WS2812].couleur = urgb_u32(ORANGE_24BITS);
|
||||
ws2812_type_gestion[NB_WS2812].led_type_gestion = PAS_DE_GESTION;
|
||||
}
|
||||
ws2812_affiche_buffer();
|
||||
}
|
||||
@ -141,6 +153,143 @@ uint32_t ws2812_mix_color(uint32_t couleur1, uint32_t couleur2, float facteur){
|
||||
uint8_t r, g, b;
|
||||
b = (couleur1 & 0xFF) * (1 - facteur) + (couleur2 & 0xFF) * facteur;
|
||||
r = ((couleur1 & 0xFF00)>> 8) * (1 - facteur) + ((couleur2 & 0xFF00)>> 8) * facteur;
|
||||
g = ((couleur1 & 0xFF0000)>> 16) * (1 - facteur) + ((couleur2 & 0xFF00)>> 16) * facteur;
|
||||
g = ((couleur1 & 0xFF0000)>> 16) * (1 - facteur) + ((couleur2 & 0xFF0000)>> 16) * facteur;
|
||||
return urgb_u32(r, g, b);
|
||||
}
|
||||
|
||||
void ws2812_set_mode(uint8_t led_id, enum led_type_gestion_t led_type_gestion, uint32_t couleur){
|
||||
if(led_id < NB_WS2812){
|
||||
ws2812_type_gestion[led_id].couleur = couleur;
|
||||
ws2812_type_gestion[led_id].led_type_gestion = led_type_gestion;
|
||||
}
|
||||
}
|
||||
|
||||
void ws2812_gestion(void){
|
||||
uint32_t temps_ref;
|
||||
uint8_t nb_cli;
|
||||
uint8_t phase_led;
|
||||
|
||||
float f;
|
||||
for(int led_id = 0; led_id < NB_WS2812; led_id++){
|
||||
switch (ws2812_type_gestion[led_id].led_type_gestion)
|
||||
{
|
||||
case PAS_DE_GESTION:
|
||||
break;
|
||||
|
||||
case LED_STABLE:
|
||||
ws2812_set_buffer(ws2812_type_gestion[led_id].couleur, led_id);
|
||||
break;
|
||||
|
||||
case LED_CLI_RAPIDE:
|
||||
if((get_absolute_time() / 50000) % 2){
|
||||
ws2812_set_buffer(ws2812_type_gestion[led_id].couleur, led_id);
|
||||
}else{
|
||||
ws2812_set_buffer(0x000000, led_id);
|
||||
}
|
||||
break;
|
||||
|
||||
case LED_CLI_NORMAL:
|
||||
if((get_absolute_time() / 200000) % 2){
|
||||
ws2812_set_buffer(ws2812_type_gestion[led_id].couleur, led_id);
|
||||
}else{
|
||||
ws2812_set_buffer(0x000000, led_id);
|
||||
}
|
||||
break;
|
||||
|
||||
case LED_CLI_LENT:
|
||||
if((get_absolute_time() / 1000000) % 2){
|
||||
ws2812_set_buffer(ws2812_type_gestion[led_id].couleur, led_id);
|
||||
}else{
|
||||
ws2812_set_buffer(0x000000, led_id);
|
||||
}
|
||||
break;
|
||||
|
||||
case LED_CLI_PANIQUE_1:
|
||||
temps_ref =100000;
|
||||
nb_cli = 1;
|
||||
phase_led =(get_absolute_time() / temps_ref) % (nb_cli*2 + 4) ;
|
||||
printf(">l:%d\n", phase_led);
|
||||
if(phase_led >= nb_cli*2){
|
||||
ws2812_set_buffer(0x000000, led_id);
|
||||
}else{
|
||||
printf(">l1:%d\n",phase_led );
|
||||
|
||||
if(phase_led % 2){
|
||||
ws2812_set_buffer(ws2812_type_gestion[led_id].couleur, led_id);
|
||||
}else{
|
||||
ws2812_set_buffer(0x000000, led_id);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case LED_CLI_PANIQUE_2:
|
||||
temps_ref =100000;
|
||||
nb_cli = 2;
|
||||
phase_led =(get_absolute_time() / temps_ref) % (nb_cli*2 + 4) ;
|
||||
if(phase_led >= nb_cli*2){
|
||||
ws2812_set_buffer(0x000000, led_id);
|
||||
}else{
|
||||
if(phase_led % 2){
|
||||
ws2812_set_buffer(ws2812_type_gestion[led_id].couleur, led_id);
|
||||
}else{
|
||||
ws2812_set_buffer(0x000000, led_id);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case LED_CLI_PANIQUE_3:
|
||||
temps_ref =100000;
|
||||
nb_cli = 3;
|
||||
phase_led =(get_absolute_time() / temps_ref) % (nb_cli*2 + 4) ;
|
||||
if(phase_led >= nb_cli*2){
|
||||
ws2812_set_buffer(0x000000, led_id);
|
||||
}else{
|
||||
if(phase_led % 2){
|
||||
ws2812_set_buffer(ws2812_type_gestion[led_id].couleur, led_id);
|
||||
}else{
|
||||
ws2812_set_buffer(0x000000, led_id);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case LED_PULSE_LENT:
|
||||
temps_ref = 3000000;
|
||||
if((get_absolute_time() / temps_ref) % 2){
|
||||
f = (float)(get_absolute_time() % temps_ref) / (float)temps_ref;
|
||||
ws2812_set_buffer(ws2812_mix_color(0, ws2812_type_gestion[led_id].couleur, f), led_id);
|
||||
}else{
|
||||
f = (float)(get_absolute_time() % temps_ref) / (float)temps_ref;
|
||||
ws2812_set_buffer(ws2812_mix_color(ws2812_type_gestion[led_id].couleur, 0, f), led_id);
|
||||
}
|
||||
break;
|
||||
|
||||
case LED_PULSE_NORMAL:
|
||||
temps_ref = 1000000;
|
||||
if((get_absolute_time() / temps_ref) % 2){
|
||||
f = (float)(get_absolute_time() % temps_ref) / (float)temps_ref;
|
||||
ws2812_set_buffer(ws2812_mix_color(0, ws2812_type_gestion[led_id].couleur, f), led_id);
|
||||
}else{
|
||||
f = (float)(get_absolute_time() % temps_ref) / (float)temps_ref;
|
||||
ws2812_set_buffer(ws2812_mix_color(ws2812_type_gestion[led_id].couleur, 0, f), led_id);
|
||||
}
|
||||
break;
|
||||
|
||||
case LED_PULSE_RAPIDE:
|
||||
temps_ref = 200000;
|
||||
if((get_absolute_time() / temps_ref) % 2){
|
||||
f = (float)(get_absolute_time() % temps_ref) / (float)temps_ref;
|
||||
ws2812_set_buffer(ws2812_mix_color(0, ws2812_type_gestion[led_id].couleur, f), led_id);
|
||||
}else{
|
||||
f = (float)(get_absolute_time() % temps_ref) / (float)temps_ref;
|
||||
ws2812_set_buffer(ws2812_mix_color(ws2812_type_gestion[led_id].couleur, 0, f), led_id);
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
25
ws2812.h
25
ws2812.h
@ -1,12 +1,37 @@
|
||||
#include "pico/stdlib.h"
|
||||
|
||||
|
||||
enum led_type_gestion_t{
|
||||
PAS_DE_GESTION,
|
||||
LED_STABLE,
|
||||
LED_CLI_RAPIDE,
|
||||
LED_CLI_NORMAL,
|
||||
LED_CLI_LENT,
|
||||
LED_CLI_PANIQUE_1,
|
||||
LED_CLI_PANIQUE_2,
|
||||
LED_CLI_PANIQUE_3,
|
||||
LED_PULSE_RAPIDE,
|
||||
LED_PULSE_NORMAL,
|
||||
LED_PULSE_LENT
|
||||
};
|
||||
|
||||
void ws2812_init(void);
|
||||
void ws2812_affiche_buffer(void);
|
||||
void ws2812_set_buffer_rgb(uint8_t rouge, uint8_t vert, uint8_t bleu, uint8_t index_led);
|
||||
void ws2812_set_rgb(uint8_t rouge, uint8_t vert, uint8_t bleu, uint8_t index_led);
|
||||
void ws2812_set_buffer_8bits(uint8_t couleur, uint8_t index_led);
|
||||
void ws2812_set_buffer(uint32_t couleur, uint8_t index_led);
|
||||
void ws2812_arc_en_ciel(void);
|
||||
void ws2812_set_led(uint8_t led, uint32_t couleur);
|
||||
void ws2812_set_mode(uint8_t led_id, enum led_type_gestion_t led_type_gestion, uint32_t couleur);
|
||||
void ws2812_gestion(void);
|
||||
uint32_t ws2812_mix_color(uint32_t couleur1, uint32_t couleur2, float facteur);
|
||||
|
||||
#define LED_ID_SD_CARD 0
|
||||
#define LED_ID_USB 1
|
||||
#define LED_ID_ASSERV 2
|
||||
#define LED_ID_DETECTION 3
|
||||
#define LED_ID_DIVERS 4
|
||||
|
||||
#define OFF_24BITS 0, 0, 0
|
||||
#define ORANGE_24BITS 4, 1, 0
|
||||
|
||||
Loading…
Reference in New Issue
Block a user