Untitled

mail@pastecode.io avatar
unknown
c_cpp
19 days ago
2.9 kB
3
Indexable
Never
#include <Adafruit_NeoPixel.h>

#define PIN_WS2812B 27
#define NUM_PIXELS 24

#define milieu 14
#define droite 12
#define gauche 13

#define temg 16
#define temd 17
#define temm 18

Adafruit_NeoPixel WS2812B(NUM_PIXELS, PIN_WS2812B, NEO_GRB + NEO_KHZ800);

bool g;
bool d;
bool s;
int t;
int a;
int b;
int c;
int debut;
int debuts;
int Debut;
int fin;
int fins;
int Fin;
int buttonstates = 0;
int lastbuttonstates = 0;
int buttonstateg = 0;
int lastbuttonstateg = 0;
int buttonstated = 0;
int lastbuttonstated = 0;

void setup() {
  pinMode(PIN_WS2812B, OUTPUT);
  pinMode(milieu, INPUT);
  pinMode(droite, INPUT);
  pinMode(gauche, INPUT);
  pinMode(temg, OUTPUT);
  pinMode(temd, OUTPUT);
  pinMode(temm, OUTPUT);
  Serial.begin(115200);
}

void loop() {
  buttonstates = digitalRead(milieu);
  if (buttonstates == HIGH) {
    s = 1;
    Serial.print("s = ");
    Serial.println(s);
    if (d == 1) Fin = 15;
    else Fin = 23;
    if (g == 1) Debut = 8;
    else Debut = 0;
    for (int i = Debut; i <= Fin; i++) {
      WS2812B.setPixelColor(i, WS2812B.Color(255, 0, c));
      WS2812B.show();
    }
  }
  if (buttonstates == LOW) {
    s = 0;
    Serial.print("s = ");
    Serial.println(s);
    Debut = 0;
    Fin = 24;
    if (g == 1) Debut = 8;
    if (d == 1) Fin = 15;
    for (int i = Debut; i <= Fin; i++) {
      WS2812B.setPixelColor(i, WS2812B.Color(0, 0, c));
      WS2812B.show();
    }
  }


  buttonstateg = digitalRead(gauche);
  if (buttonstateg != lastbuttonstateg) {
    if (buttonstateg == HIGH) {
      g = !g;
      d = 0;
      Serial.print("g = ");
      Serial.println(g);
      WS2812B.clear();
      WS2812B.show();
      debut = 0;
      fin = 7;
      delay(300);
      b = 0;
      t = millis();
    }
  }
  lastbuttonstates = buttonstates;


  buttonstated = digitalRead(droite);
  if (buttonstated != lastbuttonstated) {
    if (buttonstated == HIGH) {
      d = !d;
      g = 0;
      Serial.print("d = ");
      Serial.println(d);
      WS2812B.clear();
      WS2812B.show();
      debut = 16;
      fin = 23;
      delay(300);
      b = 0;
      t = millis();
    }
  }
  lastbuttonstates = buttonstates;


  if (g == 1 || d == 1) {
    if ((millis() - t) >= 400) {
      Serial.println("millis");
      if (s == 1) {
        if (b == 255) {
          b = 0;
          a = 255;
        } else if (b == 0) {
          b = 255;
          a = 0;
        }
      } else {
        if (b == 255) b = 0;
        else if (b == 0) b = 255;
        a = 0;
      }
      for (int i = debut; i <= fin; i++) {
        WS2812B.setPixelColor(i, WS2812B.Color(a, b, c));
        WS2812B.show();
      }
      t = millis();
    }
  }


  if (g == 1) analogWrite(temg, 220);
  else analogWrite(temg, 255);
  if (d == 1) analogWrite(temd, 220);
  else analogWrite(temd, 255);
  if (s == 1) analogWrite(temm, 220);
  else analogWrite(temm, 255);
}
Leave a Comment