69 lines
1.7 KiB
C++
Raw Normal View History

2023-10-20 20:51:54 +02:00
#include "../include/LedLib.h"
// Initialisation
// Initialization
LedLib::LedLib(int pixelCount, int pixelPin, int bright){
this->ledNb = 0;
this->strip = new Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, NEO_GRB + NEO_KHZ800);
this->strip->begin();
this->strip->show();
this->strip->setBrightness(bright);
}
// Fonction pour allumer correctement les LEDs en fonction du Rotary
// Function to manage LEDs colors according to the Rotary
2023-10-22 00:34:20 +02:00
void LedLib::actLed(int nb, int start){
2023-10-20 20:51:54 +02:00
this->ledNb = nb;
// On éteint tout
// We shut everything up
this->strip->clear();
// Allumer 0 LED ? Inutile
// Useless to light up 0 LED
if (nb != 0) {
// Boucle dans les LEDs
// Loop in LEDs
2023-10-22 00:34:20 +02:00
for (int i = start; i <= nb+start-1; i++) {
int j = i;
if(j > 24){
j -= 24;
}
2023-10-20 20:51:54 +02:00
// Une LED sur deux est blanche : heure entière, l'autre rouge pour 30m
// One LED out of two is white: whole hour, the other red for 30m
2023-10-22 00:34:20 +02:00
if (j%2 == 0) {
this->strip->setPixelColor(j, 255, 255, 255);
2023-10-20 20:51:54 +02:00
}else{
2023-10-22 00:34:20 +02:00
this->strip->setPixelColor(j, 255, 0, 0);
2023-10-20 20:51:54 +02:00
}
}
}
// Maintenant on allume
// Then light everything up
this->strip->show();
}
// Fonction qui renvoie le nombre de LEDs allumées
// Function that returns the number of LEDs lit
int LedLib::getledNB(){
return this->ledNb;
}
void LedLib::okBlink(){
2023-10-27 20:52:04 +02:00
this->strip->clear();
for(int i = 0; i < 3; i++){
for(int j = 0; j < 24; j++){
this->strip->setPixelColor(j, 0, 255, 0);
}
this->strip->show();
delay(100);
this->strip->clear();
this->strip->show();
delay(100);
}
2023-10-20 20:51:54 +02:00
}