initial commit
This commit is contained in:
commit
4a7d153391
2 changed files with 658 additions and 0 deletions
458
main.cpp
Normal file
458
main.cpp
Normal file
|
@ -0,0 +1,458 @@
|
|||
#include <FastLED.h>
|
||||
#include <DS3231.h>
|
||||
DS3231 rtc(SDA, SCL);
|
||||
Time t;
|
||||
SevSeg Display;
|
||||
const int hrs_set = A0;
|
||||
const int min_set = A1;
|
||||
const int ledPin = A3;
|
||||
|
||||
unsigned int displayNumber = 0;
|
||||
const long displayChangeInterval = 500;
|
||||
unsigned int displayPanel = 0; // 0 = time, 1 = fam's
|
||||
|
||||
unsigned long startMillis;
|
||||
unsigned long currentMillis;
|
||||
unsigned long previousMillis = 0;
|
||||
unsigned int date = 0;
|
||||
unsigned int hour = 0;
|
||||
unsigned int hrs_var = 0;
|
||||
unsigned int min_var = 0;
|
||||
int ledState = LOW;
|
||||
|
||||
//fastled
|
||||
#define NUM_LEDS 396 //7 * 9 * 6 + 6*3(points)
|
||||
#define DATA_PIN 3
|
||||
CRGB leds[NUM_LEDS]; // Define the array of leds
|
||||
|
||||
//display
|
||||
short delayFams = 10000; //chaque fam's s'affiche ce temps
|
||||
short delayTime = 5000; //l'heure s'affiche
|
||||
|
||||
void setup()
|
||||
{
|
||||
//Serial
|
||||
Serial.begin(9600);
|
||||
//RTC
|
||||
rtc.begin();
|
||||
pinMode(ledPin, OUTPUT);
|
||||
pinMode(hrs_set, INPUT_PULLUP);
|
||||
pinMode(min_set, INPUT_PULLUP);
|
||||
byte numDigits = 4;
|
||||
byte digitPins[] = {10, 11, 12, 13};
|
||||
byte segmentPins[] = {2, 3, 4, 5, 6, 7, 8, 9};
|
||||
bool resistorsOnSegments = false;
|
||||
bool updateWithDelays = false;
|
||||
byte hardwareConfig = COMMON_CATHODE;
|
||||
bool leadingZeros = true;
|
||||
bool disableDecPoint = true;
|
||||
Display.begin(hardwareConfig, numDigits, digitPins, segmentPins, resistorsOnSegments, updateWithDelays, leadingZeros, disableDecPoint);
|
||||
Display.setBrightness(100);
|
||||
//FASTLED
|
||||
FastLED.addLeds<WS2811, DATA_PIN, RGB>(leds, NUM_LEDS);
|
||||
|
||||
|
||||
//7seg
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
int getTime()
|
||||
{
|
||||
//Getting the time
|
||||
t = rtc.getTime();
|
||||
|
||||
date = t.date;
|
||||
|
||||
|
||||
hour = t.hour;
|
||||
hrs_var = t.hour;
|
||||
min_var = t.min;
|
||||
|
||||
return ; //return time
|
||||
}
|
||||
|
||||
void displayTime()
|
||||
{
|
||||
displayNumber = hour * 100 + t.min;
|
||||
Display.setdisplayNumber(displayNumber);
|
||||
Display.refreshDisplay();
|
||||
if (digitalRead(hrs_set) == LOW)
|
||||
{
|
||||
hrs_var += 1;
|
||||
if (hrs_var > 23) hrs_var = 0;
|
||||
rtc.setTime(hrs_var, min_var, 0);
|
||||
for (int i = 0; i < 1000; i ++)
|
||||
{
|
||||
Display.setdisplayNumber(displayNumber);
|
||||
Display.refreshDisplay();
|
||||
}
|
||||
}
|
||||
if (digitalRead(min_set) == LOW)
|
||||
{
|
||||
min_var += 1;
|
||||
if (min_var >= 60) min_var = 0;
|
||||
rtc.setTime(hrs_var, min_var, 0);
|
||||
for (int i = 0; i < 1000; i ++)
|
||||
{
|
||||
Display.setdisplayNumber(displayNumber);
|
||||
Display.refreshDisplay();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void displayFams(int joursRestants)
|
||||
{
|
||||
|
||||
String currentFams;
|
||||
String famsDuJour1;
|
||||
String famsDuJour2;
|
||||
int currentColor = 0; //0 = Blue; 1=Pink; 2=Yellow
|
||||
int parseJoursRestantsInt;
|
||||
|
||||
//liste
|
||||
String matrixFams[179][2] = //162 fam's, 2 colonnes : joursRestants & texte à afficher
|
||||
// on peut faire des array de strings ?
|
||||
// jour restant, fams à afficher
|
||||
{
|
||||
{"0", " 100"},
|
||||
{"0", " 100"},
|
||||
{"1", " 1"},
|
||||
{"1", " 100"},
|
||||
{"2", " 2"},
|
||||
{"2", " 102-38"},
|
||||
{"3", " 3"},
|
||||
{"3", " 103"},
|
||||
{"4", " 4-51-55"},
|
||||
{"4", " 104"},
|
||||
{"5", " 5"},
|
||||
{"5", " 105-12"},
|
||||
{"6", " 6"},
|
||||
{"6", " 106-113"},
|
||||
{"7", " 7"},
|
||||
{"7", " 107-180"},
|
||||
{"8", " 8"},
|
||||
{"8", " 190-95"},
|
||||
{"9", " 9"},
|
||||
{"9", " 109-114"},
|
||||
{"10"," 10-67"},
|
||||
{"10"," 110"},
|
||||
{"11"," 11-41"},
|
||||
{"11"," 111"},
|
||||
{"12"," 12-105"},
|
||||
{"12"," 112"},
|
||||
{"13"," 13"},
|
||||
{"13"," 113-106"},
|
||||
{"14"," 14"},
|
||||
{"14"," 114-109"},
|
||||
{"15"," 15 82"},
|
||||
{"15"," 115-31"},
|
||||
{"16"," 89"},
|
||||
{"16"," 116-160"},
|
||||
{"17"," 17"},
|
||||
{"17"," 117"},
|
||||
{"18"," 18-154"},
|
||||
{"18"," 98"},
|
||||
{"19"," 19"},//phy's
|
||||
{"19"," 119-155"},
|
||||
{"20"," 20-37-58"},
|
||||
{"20"," 120"},
|
||||
{"21"," 21-97"},
|
||||
{"21"," 121"},
|
||||
{"22"," 22-148"},
|
||||
{"22"," 122"},
|
||||
{"23"," 23-164"},
|
||||
{"23"," 123-80"},
|
||||
{"24"," 24"},
|
||||
{"24"," 124-33"},
|
||||
{"25"," 25-5-94"},
|
||||
{"25"," 125-133"},
|
||||
{"26"," 26"},
|
||||
{"26"," 126"},
|
||||
{"27"," 27"},
|
||||
{"27"," 127"},
|
||||
{"28"," 28-165"},
|
||||
{"28","128-12959"},
|
||||
{"29"," 29"},
|
||||
{"29","129-59128"},
|
||||
{"30"," 90-158"},
|
||||
{"30"," 130"},
|
||||
{"31"," 31-115"},
|
||||
{"31"," 131-99"},
|
||||
{"32"," 32"},
|
||||
{"32"," 132-168"},
|
||||
{"33"," 99-131"},
|
||||
{"33"," 133-125"},
|
||||
{"34"," 34-137"},
|
||||
{"34"," 134"},
|
||||
{"35"," 35"},
|
||||
{"35"," 135"},
|
||||
{"35"," 335"},//aarhgh
|
||||
{"36"," 36"},
|
||||
{"36"," 136-169"},
|
||||
{"37"," 137-34"},
|
||||
{"37"," 911"},
|
||||
{"38"," 38-102"},
|
||||
{"38"," 95-190"},
|
||||
{"39"," 39"},
|
||||
{"39"," 139"},
|
||||
{"40"," 40"},
|
||||
{"40","40-140-12"},
|
||||
{"41"," 41-11"},
|
||||
{"41"," 141-118"},
|
||||
{"42"," 42-52"},
|
||||
{"42"," 142"},
|
||||
{"43"," 43"},
|
||||
{"43"," 143"},
|
||||
{"44"," 44-84-88"},
|
||||
{"44"," 144"},
|
||||
{"45"," 45"},
|
||||
{"45"," 145-65"},
|
||||
{"46"," 46"},
|
||||
{"46"," 146"},
|
||||
{"47"," 47"},
|
||||
{"47"," 147"},
|
||||
{"48"," 48-81"},
|
||||
{"48"," 148-22"},
|
||||
{"49"," 49"},
|
||||
{"49"," 149-66"},
|
||||
{"50"," 50-30"},
|
||||
{"50"," 150"},
|
||||
{"51"," 51-4-55"},
|
||||
{"51"," 151"},
|
||||
{"52"," 52-42"},
|
||||
{"52"," 152-53"},
|
||||
{"53"," 53-152"},
|
||||
{"53"," 153"},
|
||||
{"54"," 54"},
|
||||
{"54"," 91"},
|
||||
{"55"," 55-4-51"},
|
||||
{"55"," 155-119"},
|
||||
{"56"," 56"},
|
||||
{"56"," 156"},
|
||||
{"57"," 57-74"},
|
||||
{"57"," 157"},
|
||||
{"58"," 58-20-37"},
|
||||
{"58"," 158-90"},
|
||||
{"59","59-129128"},
|
||||
{"59"," 159"},
|
||||
{"60"," 60-70"},
|
||||
{"60"," 160-116"},
|
||||
{"61"," 61-159"},
|
||||
{"61"," 161"},
|
||||
{"62"," 62-24"},
|
||||
{"62"," 62-24"},
|
||||
{"63"," 93"},
|
||||
{"63"," 163"},
|
||||
{"64"," 64"},
|
||||
{"64"," 164-23"},
|
||||
{"65"," 65-145"},
|
||||
{"65"," 165-28"},
|
||||
{"66"," 66-149"},
|
||||
{"66"," 96"},
|
||||
{"67"," 67-65"},
|
||||
{"67"," 167"},
|
||||
{"68"," 68"},
|
||||
{"68"," 168-132"},
|
||||
{"69"," 69"},
|
||||
{"69"," 169-136"},
|
||||
{"70"," 70-60"},
|
||||
{"70"," 170-71"},
|
||||
{"71"," 71-170"},
|
||||
{"71"," 171-173"},
|
||||
{"72"," 72"},
|
||||
{"72"," 92"},
|
||||
{"73"," 73-16"},
|
||||
{"73"," 173-171"},
|
||||
{"74"," 74-57"},
|
||||
{"74"," 94-5-25"},
|
||||
{"75"," 75"},
|
||||
{"75"," 75"},
|
||||
{"76"," 76-108"},
|
||||
{"76"," 76-108"},
|
||||
{"77"," 77"},
|
||||
{"77"," 87"},
|
||||
{"78"," 78-96"},
|
||||
{"78"," 178-138"},
|
||||
{"79"," 79"},
|
||||
{"79"," 97-21"},
|
||||
{"80"," 83"},
|
||||
{"80"," 85"},
|
||||
{"81"," 84-44-88"},
|
||||
{"81"," 88-84-44"}
|
||||
};
|
||||
|
||||
//récupérer la date
|
||||
|
||||
//transformer en jours restants
|
||||
|
||||
//couleurs spéciales
|
||||
if(currentFams == " 142")
|
||||
{
|
||||
currentColor = 1;
|
||||
Serial.println("Couleur : Rose");
|
||||
}
|
||||
else if(currentFams = " 94-5-25")
|
||||
{
|
||||
currentColor = 2;
|
||||
Serial.println("Couleur : Jaune");
|
||||
}
|
||||
else
|
||||
{
|
||||
currentColor = 0;
|
||||
Serial.println("Couleur : Rouge");
|
||||
}
|
||||
|
||||
if(joursRestants == 35) // exeption pour les fams 35, 135 et 335
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
famsDuJour1 = matrixFams[joursRestants][2];
|
||||
famsDuJour2 = matrixFams[joursRestants+1][2];
|
||||
|
||||
7segment(famsDuJour1);
|
||||
delay(delayFams);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void 7segment(char displayText[9], short displayColor, bool displayPoints) //2 strings
|
||||
{
|
||||
// décomposer displayTest en une matrice de caractères
|
||||
int segmentsChar[9]
|
||||
|
||||
for(int i=0; i<9; i++)
|
||||
{
|
||||
int temp = 0;
|
||||
temp = displayText
|
||||
segmentChar[i] =
|
||||
}
|
||||
|
||||
//transformer la matrice de caracteres en une matrice de numéros
|
||||
//avec
|
||||
//char 0 = 0
|
||||
//char 1 = 1
|
||||
//etc
|
||||
//char - = 10
|
||||
|
||||
int displayNumCode[];
|
||||
|
||||
|
||||
//quels segments allumer pour chaque caractere
|
||||
// 6
|
||||
// ___
|
||||
// 5| |7
|
||||
// |_4_|
|
||||
// 1| |3
|
||||
// |___|
|
||||
// 2
|
||||
|
||||
|
||||
bool matrix7seg[11][7] = //11 charactères, 012345679-, 7 seg
|
||||
// 1 2 3 4 5 6 7
|
||||
{ {1,1,1,0,1,1,1}, //char 0
|
||||
{0,0,1,0,0,0,1}, //char 1
|
||||
{1,1,0,1,0,1,1}, //char 2 continuer ici
|
||||
{0,1,1,1,0,1,1}, //char 3
|
||||
{0,0,1,1,1,0,1}, //char 4
|
||||
{0,1,1,1,1,1,0}, //char 5
|
||||
{1,1,1,1,1,1,0}, //char 6
|
||||
{0,0,1,0,0,1,1}, //char 7
|
||||
{1,1,1,1,1,1,1}, //char 8
|
||||
{0,1,1,1,1,1,1}, //char 9
|
||||
{0,0,0,1,0,0,0} //char -
|
||||
};
|
||||
|
||||
//afficher les caracteres individuels
|
||||
|
||||
int indiceLed = 0;
|
||||
for(int i=0; i<9; i++) //chaque numéro
|
||||
{
|
||||
for(int j = 0; j<7; j++) //chaque segment
|
||||
{
|
||||
if(matrix7seg[displayNumCode][j] == 1)
|
||||
{
|
||||
for(indiceLed; k<6; k++) //chaque led
|
||||
{
|
||||
if(displayColor == 0) //rouge
|
||||
{
|
||||
leds[i*7*6 +j*6 + k] = CRGB::Red;
|
||||
}
|
||||
else if(displayColor == 1) //rose
|
||||
{
|
||||
leds[i*7*6 +j*6 + k] = CRGB::Pink;
|
||||
}
|
||||
else if(displayColor == 2) //jaune
|
||||
{
|
||||
leds[i*7*6 +j*6 + k] = CRGB::Yellow;
|
||||
}
|
||||
indiceLed = indiceLed+1
|
||||
}
|
||||
}
|
||||
else if(matrix7seg[displayNumCode][j] == 0)
|
||||
{
|
||||
|
||||
}
|
||||
indiceLed = indiceLed+6
|
||||
}
|
||||
indiceLed = indiceLed+()
|
||||
}
|
||||
|
||||
|
||||
//points
|
||||
|
||||
if(displayPoints == false)
|
||||
{
|
||||
//éteindre les points
|
||||
for(int l=379; l<=396; l++)
|
||||
{
|
||||
leds[l] = CRGB::Black;
|
||||
}
|
||||
}
|
||||
else if(displayPoints == true)
|
||||
{
|
||||
//allumer les points
|
||||
for(int l=379; l<=396; l++)
|
||||
{
|
||||
leds[l] = CRGB::displayColor; //displaycolor est un string
|
||||
}
|
||||
}
|
||||
|
||||
FastLED.show();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
//get the time
|
||||
|
||||
//display the time
|
||||
|
||||
//get the fams
|
||||
|
||||
//display the fam's
|
||||
|
||||
|
||||
unsigned long currentMillis = millis();
|
||||
if (currentMillis - previousMillis >= displayChangeInterval)
|
||||
{
|
||||
previousMillis = currentMillis;
|
||||
if (ledState == LOW)
|
||||
{
|
||||
ledState = HIGH;
|
||||
}
|
||||
else
|
||||
{
|
||||
ledState = LOW;
|
||||
}
|
||||
digitalWrite(ledPin, ledState);
|
||||
}
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue