first commit
This commit is contained in:
189
LED_STRIP_02/LED_STRIP_02.ino
Normal file
189
LED_STRIP_02/LED_STRIP_02.ino
Normal file
@@ -0,0 +1,189 @@
|
||||
#include <Adafruit_NeoPixel.h> // Charge la librairie Neo Pixel d'Adafruit utilisé pour piloter le ruban de LED
|
||||
|
||||
#define PIXEL_PIN 6 // On définit le pin où est connecté la patte DATA du bandeau
|
||||
#define PIXEL_COUNT 17 // On définit le nombre de LED compris sur le Ruban de LED soit 150 pour le ruban de 5m50
|
||||
|
||||
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, NEO_BRG + NEO_KHZ400); // Paramètre l'objet strip qui correspond à toute les LED du ruban
|
||||
|
||||
int FIRE[PIXEL_COUNT][3];
|
||||
|
||||
void setup() {
|
||||
strip.begin(); // Lance la connection
|
||||
strip.show(); // Initialise toute les led à 'off'
|
||||
|
||||
for(int i = 0 ; i < PIXEL_COUNT ; i++) {
|
||||
FIRE[i][0] = random() * 255;
|
||||
FIRE[i][1] = random() * 255;
|
||||
FIRE[i][2] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Définition des couleurs */
|
||||
int RED[3] = {255, 0, 0}; // Couleur Rouge
|
||||
int GREEN[3] = {0, 255, 0}; // Couleur Verte
|
||||
int CYAN[3] = {0, 255, 255}; // Couleur Cyan
|
||||
int YELLOW[3] = {255, 125, 0}; // Couleur Jaune
|
||||
int ORANGE[3] = {255, 40, 0}; // Couleur Orange
|
||||
int PURPLE[3] = {255, 0 , 255}; // Couleur Violette
|
||||
int PINK[3] = {255, 0, 100}; // Couleur Rose
|
||||
int BLUE[3] = {0, 0, 255}; // Couleur Bleu
|
||||
int WHITE[3] = {255, 255, 255}; // Couleur Blanche
|
||||
int OFF[3] = {0, 0, 0}; // Éteint
|
||||
|
||||
void loop() {
|
||||
strip.setBrightness(100); // Règle la luminosité à 100 % de la luminosité maximale
|
||||
//allLeds(GREEN);
|
||||
|
||||
//fire();
|
||||
|
||||
for(int i = 0 ; i < PIXEL_COUNT ; i++) {
|
||||
oneLed(i, RED);
|
||||
delay(100);
|
||||
oneLed(i, OFF);
|
||||
}
|
||||
|
||||
//delay(5000);
|
||||
allBicolor(BLUE,RED);
|
||||
delay(1000);
|
||||
progressiveUp(20, BLUE);
|
||||
delay(1000);
|
||||
changeColor(10, BLUE, RED);
|
||||
delay(1000);
|
||||
ledUp(20, RED);
|
||||
ledUp(20, GREEN);
|
||||
ledUp(20, BLUE);
|
||||
ledUp(20, ORANGE);
|
||||
allLeds(OFF);
|
||||
chenillardUp(50, GREEN);
|
||||
chenillardUp(50, BLUE);
|
||||
|
||||
}
|
||||
|
||||
void oneLed(int number, int COLOR[])
|
||||
{
|
||||
strip.setPixelColor(number, COLOR[0], COLOR[1], COLOR[2]);
|
||||
strip.show();
|
||||
}
|
||||
void allLeds(int COLOR[])
|
||||
{
|
||||
for(int i = 0 ; i < PIXEL_COUNT ; i++)
|
||||
{
|
||||
strip.setPixelColor(i, COLOR[0], COLOR[1], COLOR[2]);
|
||||
}
|
||||
strip.show();
|
||||
}
|
||||
|
||||
void allBicolor(int COLOR_LEFT[], int COLOR_RIGHT[])
|
||||
{
|
||||
for(int i = 0 ; i < PIXEL_COUNT/2 ; i++)
|
||||
{
|
||||
strip.setPixelColor(i, COLOR_LEFT[0], COLOR_LEFT[1], COLOR_LEFT[2]);
|
||||
}
|
||||
|
||||
for(int i = PIXEL_COUNT/2 ; i < PIXEL_COUNT ; i++)
|
||||
{
|
||||
strip.setPixelColor(i, COLOR_RIGHT[0], COLOR_RIGHT[1], COLOR_RIGHT[2]);
|
||||
}
|
||||
strip.show();
|
||||
}
|
||||
|
||||
void progressiveUp(int temps, int COLOR[])
|
||||
{
|
||||
for(int lumi = 0 ; lumi < 100 ; lumi++)
|
||||
{
|
||||
for(int i = 0 ; i < 150 ; i++)
|
||||
{
|
||||
strip.setPixelColor(i, COLOR[0], COLOR[1], COLOR[2]);
|
||||
}
|
||||
strip.setBrightness(lumi);
|
||||
strip.show();
|
||||
delay(temps);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void changeColor(int temps, int colorDebut[3], int colorFin[3])
|
||||
{
|
||||
|
||||
int color[3] = {0};
|
||||
|
||||
color[0] = colorDebut[0];
|
||||
color[1] = colorDebut[1];
|
||||
color[2] = colorDebut[2];
|
||||
|
||||
while(color[0] != colorFin[0] || color[1] != colorFin[1] || color[2] != colorFin[2])
|
||||
{
|
||||
|
||||
if(color[0] > colorFin[0])
|
||||
{
|
||||
color[0]--;
|
||||
}
|
||||
else if(color[0] < colorFin[0])
|
||||
{
|
||||
color[0]++;
|
||||
}
|
||||
|
||||
if(color[1] > colorFin[1])
|
||||
{
|
||||
color[1]--;
|
||||
}
|
||||
else if(color[1] < colorFin[1])
|
||||
{
|
||||
color[1]++;
|
||||
}
|
||||
|
||||
if(color[2] > colorFin[2])
|
||||
{
|
||||
color[2]--;
|
||||
}
|
||||
else if(color[2] < colorFin[2])
|
||||
{
|
||||
color[2]++;
|
||||
}
|
||||
|
||||
delay(temps);
|
||||
allLeds(color);
|
||||
}
|
||||
}
|
||||
|
||||
void ledUp(int temps, int color[3])
|
||||
{
|
||||
for(int i = 0 ; i < PIXEL_COUNT ; i++)
|
||||
{
|
||||
strip.setPixelColor(i, color[0], color[1], color[2]);
|
||||
strip.show();
|
||||
strip.setPixelColor(i, 0, 0, 0);
|
||||
strip.show();
|
||||
delay(temps);
|
||||
}
|
||||
}
|
||||
|
||||
void chenillardUp(int temps, int color[3])
|
||||
{
|
||||
for(int i = 0 ; i < PIXEL_COUNT ; i++)
|
||||
{
|
||||
strip.setPixelColor(i, color[0], color[1], color[2]);
|
||||
strip.show();
|
||||
delay(temps);
|
||||
}
|
||||
}
|
||||
|
||||
void fire()
|
||||
{
|
||||
// A B X C D
|
||||
// D
|
||||
// X(t) = (A(t-1) + B(t-1) + C(t-1) + D(t-1)) / 4
|
||||
|
||||
for(int j = 0 ; j < 2500; j++) {
|
||||
for(int i = 0 ; i < PIXEL_COUNT; i++) {
|
||||
// FIRE[i][0] = (FIRE[i-2][0]+ FIRE[i-1][0] + FIRE[i+1][0] + FIRE[i+2][0]) / 4;
|
||||
|
||||
FIRE[i][1] = (FIRE[i-2][1]+ FIRE[i-1][1] + FIRE[i+1][1] + FIRE[i+2][1] + random() * 255) / 5;
|
||||
strip.setPixelColor(i, FIRE[i][0], FIRE[i][1], FIRE[i][2]);
|
||||
}
|
||||
strip.show();
|
||||
|
||||
delay(200);
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user