#include <LedControlMS.h>
#include <Adafruit_NeoPixel.h>
#define NUM_LEDS 34
#define StripAffPin 8
#define NBTaff 9
//pin
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, StripAffPin, NEO_GRB + NEO_KHZ800);
//afficheur led
int Select = 3;
bool saturation = 1;
LedControl Module = LedControl(2, 3, 4, 8);
bool X = 0;
const byte A[8] = { X, 0x18, 0x3B, 0x66, 0x66, 0x7E, 0x66, 0x66 };
const byte D[8] = { X, 0xF8, 0x6C, 0x66, 0x66, 0x66, 0x6C, 0xF8 };
const byte E[8] = { X, 0xFE, 0x62, 0x68, 0x78, 0x68, 0x62, 0xFE };
const byte F[8] = { X, 0xFE, 0x62, 0x68, 0x78, 0x68, 0x60, B11110000 };
const byte M[8] = { X, B11000110, B11101110, 0xFE, 0xFE, B11010110, B11000110, B11000110 };
const byte N[8] = { X, B11000110, B11100110, B11110110, B11011110, B11001110, B11000110, B11000110 };
const byte O[8] = { X, B00111000, 0x6C, B11000110, B11000110, B11000110, 0x6C, B00111000 };
const byte R[8] = { X, B11111100, 0x66, 0x66, B01111100, 0x6C, 0x66, B11100110 };
const byte T[8] = { X, 0x7E, B01011010, 0x18, 0x18, 0x18, 0x18, B00111100 };
const byte U[8] = { X, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, B00111100 };
const byte V[8] = { X, 0x66, 0x66, 0x66, 0x66, 0x66, B00111100, 0x18 };
const byte Z[8] = { X, 0xFE, B10000110, B00001100, 0x18, B00110000, 0x62, 0xFE };
const byte Ea[8] = { 0x18, 0xFE, 0x62, 0x68, 0x78, 0x68, 0x62, 0xFE };
const byte Minus[8] = { X, X, X, 0x7E, X, X, X, X };
const byte digits[10][8] = {
{ B01111100, B10000010, B10000010, B10000010, B10000010, B10000010, B01111100, X },
{ B00010000, B00110000, B00010000, B00010000, B00010000, B00010000, 0x7E, X },
{ 0x7E, B00000010, B00000010, 0x7E, B01000000, B01000000, 0x7E, X },
{ 0x7E, B00000010, B00000010, 0x7E, B00000010, B00000010, 0x7E, X },
{ B01000000, B01000000, B01000000, 0x7E, B00010000, B00010000, B00010000, X },
{ 0x7E, B01000000, B01000000, 0x7E, B00000010, B00000010, 0x7E, X },
{ 0x7E, B01000000, B01000000, 0x7E, B01000010, B01000010, 0x7E, X },
{ B01111100, B00000100, B00000100, B00000100, B00000100, B00000100, B00000100, X },
{ 0x7E, B01000010, B01000010, 0x7E, B01000010, B01000010, 0x7E, X },
{ 0x7E, B01000010, B01000010, 0x7E, B00000010, B00000010, 0x7E, X },
};
const byte * tabOuvert[] = { nullptr, O, U, V, E, R, T, nullptr };
const byte * tabFerme[] = { nullptr, F, E, R, M, Ea, nullptr, nullptr };
const byte * tabAttendre[] = { A, T, T, E, N, D, R, E };
const byte * tabEntrez[] = { nullptr, E, N, T, R, E, Z, nullptr };
const byte * tabReset[] = { nullptr, R, E, Z, E, T, nullptr, nullptr };
const byte ** words[] = { tabOuvert, tabFerme, tabAttendre, tabEntrez, tabReset };
enum idMessage {
OUVERT = 0,
FERME,
ATTENDRE,
ENTREZ,
RESET
};
//
int idx = 0;
//
const int g_seuilCapteur = 200;
const int g_maxPersonnes = 20;
const int g_delayReset = 2000;
// Which pin on the Arduino is connected to the NeoPixels?
#define BANDEAU_PIN 5 // On Trinket or Gemma, suggest changing this to 1
// How many NeoPixels are attached to the Arduino?
#define BANDEAU_NUMLEDS 32 // Popular NeoPixel ring size
Adafruit_NeoPixel pixels(BANDEAU_NUMLEDS, BANDEAU_PIN, NEO_GRB + NEO_KHZ800);
void setup() {
Serial.begin(9600); //innitialisation debugmode
strip.setBrightness(100);
// These lines are specifically to support the Adafruit Trinket 5V 16 MHz.
// Any other board, you can remove this part (but no harm leaving it):
#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
clock_prescale_set(clock_div_1);
#endif
// END of Trinket-specific code.
pixels.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
}
unsigned long lastTime = 0;
struct EtatCapteur {
public:
EtatCapteur( int _id )
: idInput(_id), prevValue(0), status(0) {
}
void Reset() {
status = 0;
prevValue = 0;
}
void Update() {
int value = analogRead( idInput );
int delta = value - prevValue;
prevValue = value;
// -> front bas
if ( (status == 1) && (delta > g_seuilCapteur) ) {
status = 2;
}
// -> front haut
if ( (status == 0) && (delta < - g_seuilCapteur) ) {
status = 1;
}
}
bool SomethingHappened() {
return status > 0;
}
private:
// data
const int idInput;
int status;
int prevValue;
};
struct EtatCapteurs {
enum idDirection {
RIEN = 0,
ENTREE,
SORTIE
};
EtatCapteurs( int _idE, int _idI )
: exterieur(_idE), interieur(_idI), counterMS(0), compteurPersonnes(19), direction(RIEN) {
}
void Update(unsigned int _deltaMS ) {
interieur.Update();
exterieur.Update();
// Compteur pour reset si delai expiré
if ( interieur.SomethingHappened() || exterieur.SomethingHappened() ) {
counterMS += _deltaMS;
}
if ( direction == RIEN ) {
if ( exterieur.SomethingHappened() && !interieur.SomethingHappened() ) {
direction = ENTREE;
}
if ( interieur.SomethingHappened() && !exterieur.SomethingHappened() ) {
direction = SORTIE;
}
}