Actualiser code/Feu_tricolor_v1.ino

This commit is contained in:
Pierre GIMENEZ 2023-09-21 09:52:34 +02:00
parent d3ad4f800e
commit 962b279c9f

View File

@ -1,86 +1,89 @@
#include <FastLED.h>
#include "avdweb_Switch.h"
#define LED_PIN 3
#define NUM_LEDS 88
CRGB leds[NUM_LEDS];
int button1pin=0; // Déclarations des pins des boutons.
int button2pin=1;
int button3pin=2;
int button1State = 0; // Give pushbutton a value
int button2State = 0; // Give pushbutton a value
int button3State = 0; // Give pushbutton a value
void setup() {
Serial.begin(9600);
pinMode(button1pin, INPUT); // configure la broche 7 en ENTREE
pinMode(button2pin, INPUT); // configure la broche 7 en ENTREE
pinMode(button3pin, INPUT); // configure la broche 7 en ENTREE
digitalWrite(button1pin, LOW);
digitalWrite(button2pin, LOW);
digitalWrite(button2pin, LOW);
FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS);
FastLED.setMaxPowerInVoltsAndMilliamps(5, 500);
FastLED.clear();
FastLED.show();
}
void loop() {
button1State = digitalRead(button1pin);
button2State = digitalRead(button2pin);
button3State = digitalRead(button3pin);
if(button1State == HIGH) {
FastLED.clear();
for (int i=0; i < 6; i++) {
leds[i] = CRGB(255,0,0);}
for (int j=8; j < 14; j++) {
leds[j] = CRGB(0,0,0);}
for (int k=16; k < 38; k++) {
leds[k] = CRGB(0,0,0);}
for (int l=38; l < 50; l++) {
leds[l] = CRGB(255,0,0);}
for (int m=50; m < 82; m++) {
leds[m] = CRGB(0,0,0);}
for (int n=82; n < 88; n++) {
leds[n] = CRGB(255,0,0);}
FastLED.show();
}
if(button2State == HIGH) {
FastLED.clear();
Serial.print("button 2 appuyé ");
for (int i=0; i < 6; i++) {
leds[i] = CRGB::Black;}
for (int j=8; j < 14; j++) {
leds[j] = CRGB::Orange;}
for (int k=14; k < 18; k++) {
leds[k] = CRGB(0,0,0);}
for (int l=30; l < 36; l++) {
leds[l] = CRGB::Orange;}
for (int m=52; m < 58; m++) {
leds[m] = CRGB::Orange;}
for (int n=74; n < 80; n++) {
leds[n] = CRGB::Orange;}
FastLED.show();
delay(500);
for (int o=0; o < 88 ; o++) {
leds[o] = CRGB::Black;}
FastLED.show();
delay(500);
}
if(button3State == HIGH) {
FastLED.clear();
Serial.print("button 3 appuyé ");
for (int p=16; p < 28; p++) {
leds[p] = CRGB::Green;}
for (int q=60; q < 72; q++) {
leds[q] = CRGB::Green;}
FastLED.show();
}
}
#include <FastLED.h>
#include "avdweb_Switch.h"
#define LED_PIN 3
#define NUM_LEDS 88
CRGB leds[NUM_LEDS];
// Déclarations des pins des boutons.
int button1pin=0;
int button2pin=1;
int button3pin=2;
int button1State = 0;
int button2State = 0;
int button3State = 0;
void setup() {
Serial.begin(9600);
pinMode(button1pin, INPUT); // configure la broche 0 en ENTREE
pinMode(button2pin, INPUT); // configure la broche 1 en ENTREE
pinMode(button3pin, INPUT); // configure la broche 2 en ENTREE
digitalWrite(button1pin, LOW);
digitalWrite(button2pin, LOW);
digitalWrite(button2pin, LOW);
FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS);
FastLED.setMaxPowerInVoltsAndMilliamps(5, 500);
FastLED.clear();
FastLED.show();
}
void loop() {
button1State = digitalRead(button1pin);
button2State = digitalRead(button2pin);
button3State = digitalRead(button3pin);
// Si le bouton 1 est appuyé alors la partie du bas s'allume en rouge
if(button1State == HIGH) {
FastLED.clear();
for (int i=0; i < 6; i++) {
leds[i] = CRGB(255,0,0);}
for (int j=8; j < 14; j++) {
leds[j] = CRGB(0,0,0);}
for (int k=16; k < 38; k++) {
leds[k] = CRGB(0,0,0);}
for (int l=38; l < 50; l++) {
leds[l] = CRGB(255,0,0);}
for (int m=50; m < 82; m++) {
leds[m] = CRGB(0,0,0);}
for (int n=82; n < 88; n++) {
leds[n] = CRGB(255,0,0);}
FastLED.show();
}
if(button2State == HIGH) { // Si le bouton 2 est appuyé, le milieu s'allume en orange clignottant
FastLED.clear();
Serial.print("button 2 appuyé ");
for (int i=0; i < 6; i++) {
leds[i] = CRGB::Black;}
for (int j=8; j < 14; j++) {
leds[j] = CRGB::Orange;}
for (int k=14; k < 18; k++) {
leds[k] = CRGB(0,0,0);}
for (int l=30; l < 36; l++) {
leds[l] = CRGB::Orange;}
for (int m=52; m < 58; m++) {
leds[m] = CRGB::Orange;}
for (int n=74; n < 80; n++) {
leds[n] = CRGB::Orange;}
FastLED.show();
delay(500);
for (int o=0; o < 88 ; o++) {
leds[o] = CRGB::Black;}
FastLED.show();
delay(500);
}
if(button3State == HIGH) { // Si le bouton 3 est appuyé, le haut s'allume en vert
FastLED.clear();
Serial.print("button 3 appuyé ");
for (int p=16; p < 28; p++) {
leds[p] = CRGB::Green;}
for (int q=60; q < 72; q++) {
leds[q] = CRGB::Green;}
FastLED.show();
}
}