1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424
| //----------
//Librairies
//----------
#include <Adafruit_NeoPixel.h>
#include <FastLED.h>
//Broches d'entrées
const byte EclairageJour = 7; //broche 7 en entrée Feux de jour de "INTER 3 POS G2-3(jaune)" (constante sur 8 bits (base de calcul minimale de l'arduino)
const byte EclairageMat = 5; // broche 5 en entrée éclairage du mât + reports latéraux de "INTER MAT"
const byte ClignoDroit = 2; // broche 2 en entrée pour le cligno droit de "INTER 3 POS D2-1(vert/blanc)"
const byte ClignoGauche = 3; // broche 3 en entrée pour le cligno gauche de "INTER 3 POS D2-3(vert/noir)"
const byte Frein = 4; // broche 4 en entrée pour les freins (G && D)
//const byte CdeEcran = 8; // broche 8 en entrée pour la commande de l'affichage de l'écran de "BP G1-3(vert/jaune)"
const byte EclairageNuit = 6; // broche 6 en entrée pour la commande du feu fixe de nuit à l'arrière de "INTER 3 POS G2-1(rouge/jaune)"
//Initialisation des variables d'entrée
char EtatFeuxJour = HIGH; //INTER 3 POS G2-3 à 5v
char EtatFeuxMat = HIGH; //INTER MAT à 5v
char EtatClignoDroit = LOW; //INTER 3 POS D2-1 à 0v
char EtatClignoGauche = LOW; //INTER 3 POS D2-3 à 0v
char EtatFrein = LOW; //INTER FREINS à 0v
char EtatFeuxNuit = HIGH; //INTER 3 POS G2-1 à 5v
int i;
//Broches de sorties
#define Led_ar_Haut 10 // broche 10 en sortie (PWM sur Tor) éclairage leds rouges cligno arrière
#define Led_mat 9 // broche 9 en sortie (PWM sur Tor) éclairage mât et reports latéraux
#define Led_av_adr 12 //broche 12 bandeau avant clignotants
#define Led_ar_adr 13 //broche 13 bandeau arrière clignotants
#define Led_ar_Bas 11 // borche 11 en sortie (PWM sur Tor) leds rouges arrière fixe + frein
// L'éclairage de puissance avant est géré directement par les interrupteurs et les relais 12v
//Détermination du partage des bandeaux de leds adressables avant et arrière pour les feux de direction et les feux de jour.
#define Num_leds 144 //définition du nombre de led sur chaque bandeau adressable
byte debut = 0; //Led 1 du bandeau
byte droite = 47; //Led 48 du bandeau, limite feu droit
byte milieu = 72; //Led milieu de bandeau, départ feu de jour
byte gauche = 96; //Led 97 du bandeau, limite feu gauche
byte fin = 143; //Led 144 du bandeau
//Variables de gestion des leds adressables (indicateurs de direction et feux de jour)
CRGB AV_leds[Num_leds];
CRGB AR_leds[Num_leds];
/*------------------------------------------------------------------------
//Fonction d'initialisation de la carte contenant le code d'initialisation,
//n'est éxécutée qu'une seule fois au démarrage de la carte.
//Identification des I/O et autres réglages.
------------------------------------------------------------------------*/
void setup() {
//Initialisation des variables en entrée
pinMode(EclairageJour, INPUT);
pinMode(EclairageMat, INPUT);
pinMode(ClignoGauche, INPUT);
pinMode(ClignoDroit, INPUT);
pinMode(Frein, INPUT);
pinMode(EclairageNuit, INPUT);
//Initialisation des variables en sortie
pinMode(Led_mat, OUTPUT);
pinMode(Led_ar_Haut, OUTPUT);
pinMode(Led_ar_Bas, OUTPUT);
pinMode(Led_av_adr, OUTPUT);
pinMode(Led_ar_adr, OUTPUT);
//renseignement des librairies avec le type de LED, les paramètres d'entrée LED_PIN et NUM_LED
FastLED.addLeds<WS2812B, Led_av_adr, GRB>(AV_leds, Num_leds); //bandeau avant
FastLED.addLeds<WS2812B, Led_ar_adr, GRB>(AR_leds, Num_leds); //bandeau arrière
}
//Fonction allumage des clignotants gauches
void ClignotantGauche (){
for (i = 0; i <= 47; i++){
AV_leds[fin-i] = CRGB (255,115,0); //Allumage des leds avant en orange
AR_leds[gauche+i] = CRGB (255,115,0); //Allumage des leds arrières en orange
FastLED.show();
delay(0);
}
for (i = 0; i <= 47; i++){
AV_leds[fin-i] = CRGB (0,0,0); //Extinction des leds avant
AR_leds[gauche+i] = CRGB (0,0,0); //Extinction des leds arrière
FastLED.show();
delay(0);
}
}
//Fonction allumage des clignotants droits
void ClignotantDroit() {
for (i = 0; i <= 47; i++) {
AV_leds[debut+i] = CRGB (255,115,0); //Allumage des leds avant en orange
AR_leds[droite-i] = CRGB (255,115,0); //Allumage des leds arrière en orange
FastLED.show();
delay(0);
}
for (i = 0; i <= 47; i++) {
AV_leds[debut+i] = CRGB (0,0,0); //Extinction des leds avant
AR_leds[droite-i] = CRGB (0,0,0); //Extinction des leds arrière
FastLED.show();
delay(0);
}
}
//Fonction allumage des feux de détresse
void FeuxDetresse() {
for(i = 0 ; i <= 47; i++){
AV_leds[fin-i] = CRGB (255,115,0); //Allumage des leds avant gauche en orange
AR_leds[gauche+i] = CRGB (255,115,0); //Allumage des leds arrière gauche en orange
AV_leds[debut+i] = CRGB (255,115,0); //Allumage des leds avant droite en orange
AR_leds[droite-i] = CRGB (255,115,0); //Allumage des leds arrière droite en orange
FastLED.show();
delay(0);
}
for(i = 0 ; i <= 47; i++){
AV_leds[fin-i] = CRGB (0,0,0); //Extinction des leds
AR_leds[gauche+i] = CRGB (0,0,0);
AV_leds[debut+i] = CRGB (0,0,0);
AR_leds[droite-i] = CRGB (0,0,0);
FastLED.show();
delay(0);
}
}
//Fonction allumage des feux de jour avant sur adr
void FeuxJourAvantCligno() {
FastLED.setBrightness(32);
for(i = 0 ; i <= 24; i++){
AV_leds[milieu+i] = CRGB (255, 255, 255); //Allumage des leds avant en blanc du milieu vers la gauche
AV_leds[milieu-i] = CRGB (255, 255, 255); //Allumage des leds avant en blanc du milieu vers la droite
FastLED.show();
}
for(i = 0 ; i <= 24; i++){
AV_leds[milieu+i] = CRGB (0, 0, 0); //Extinction des leds
AV_leds[milieu-i] = CRGB (0, 0, 0);
FastLED.show();
}
}
/*/Fonction allumage des feux de jour arrière sur adr
void FeuxJourArriereCligno(){
FastLED.setBrightness(32);
for(i = 0 ; i <= 24; i++){
AR_leds[milieu+i] = CRGB (255, 0, 0); //Allumage des leds arrière en rouge du milieu vers la gauche
AR_leds[milieu-i] = CRGB (255, 0, 0); //Allumage des leds arrière en rouge du milieu vers la droite
FastLED.show();
}
for(i = 0 ; i <= 24; i++){
AR_leds[milieu+i] = CRGB (0, 0, 0); //Extinction des leds
AR_leds[milieu-i] = CRGB (0, 0, 0);
FastLED.show();
}
}
*/
//Fonction allumage fixe des feux de jour avant adr et arrière adr lors de l'utilisation des indicateurs de direction
void FeuxJourFixe() {
FastLED.setBrightness(32);
for(i = 0 ; i <= 24; i++){
AV_leds[milieu+i] = CRGB (255, 255, 255); //Allumage fixe des leds avant en blanc
AV_leds[milieu-i] = CRGB (255, 255, 255); //Allumage fixe des leds avant en blanc
AR_leds[milieu+i] = CRGB (255, 0, 0); //Allumage fixe des leds arrière en rouge
AR_leds[milieu-i] = CRGB (255, 0, 0); //Allumage fixe des leds arrière en rouge
FastLED.show();
}
}
//Fonction allumage feux rouge arrière clignotant de jour
void Feuxjour12Vcligno(){
analogWrite(Led_ar_Bas, 128); //Allumage des leds rouges arrières clignotantes à 50% de puissance
analogWrite(Led_ar_Haut, 128);
delay(250);
analogWrite(Led_ar_Bas, 0); //Extinction des leds rouges arrières clignotantes
analogWrite(Led_ar_Haut, 0);
delay(250);
}
//Fonction allumage feux stop
void FeuxStopON(){
analogWrite(Led_ar_Haut, 255); //Allumage des leds rouges arrières hautes à 100% de puissance
analogWrite(Led_ar_Bas, 255); //Allumage des leds rouges arrières basses à 100% de puissance
}
void FeuxStopOFF(){
// digitalWrite(Led_ar_Haut, LOW); //Extinction des leds rouges arrières hautes
// digitalWrite(Led_ar_Bas, LOW); //Extinction des leds rouges arrières basses
analogWrite(Led_ar_Haut, 0); //Extinction des leds rouges arrières hautes
analogWrite(Led_ar_Bas, 0); //Extinction des leds rouges arrières basses
}
//Fonction allumage feux de nuit
void FeuxNuitON(){
// digitalWrite(Led_ar_Haut, HIGH); //Extinction des leds rouges arrières hautes
// digitalWrite(Led_ar_Bas, HIGH); //Extinction des leds rouges arrières basses
analogWrite(Led_ar_Haut, 255); //Allumage des leds rouges arrières fixes à 50% de puissance
analogWrite(Led_ar_Bas, 255); //Allumage des leds rouges arrières cligno à 50% de puissance
}
//Fonction allumage du mat et des reports latéraux
void FeuxMatON(){
analogWrite(Led_mat, 255); //Allumage des leds à 75% de puissance (couleur définie par tansistors)
delay(250);
analogWrite(Led_mat, 0); //Extinction des leds
delay(250);
}
/*----------------------------------------------------------------
//Fonction principale du code, elle se répète en boucle à l'infini.
//Elle contient toutes les insctruction du programme.
----------------------------------------------------------------*/
void loop() {
//Lecture de l'état des entrées
EtatFeuxJour = digitalRead(EclairageJour); //Inter Eclairage PIN 7
EtatFeuxMat = digitalRead(EclairageMat); //Inter Eclairage PIN 5
EtatClignoDroit = digitalRead(ClignoDroit); //Inter ClignoDroit PIN 2
EtatClignoGauche = digitalRead(ClignoGauche); //Inter ClignoGauche PIN 3
EtatFrein = digitalRead(Frein); //Inters Frein PIN 4
EtatFeuxNuit = digitalRead(EclairageNuit); //Inter Eclairage Nuit PIN 6
//Initialisation de l'état du bouton virtuel pour choix du programme à exécuter
char EtatBouton = 10;
//Attribution d'une valeur à EtatBouton en fonction de la lecture des entrées
if (EtatFeuxJour == HIGH && EtatFeuxNuit == HIGH){ //Pas d'éclairage
EtatBouton = 0;
}
else if (EtatFeuxJour == LOW && EtatFeuxNuit == HIGH){ //Eclairage de jour
EtatBouton = 1;
}
else if (EtatFeuxJour == HIGH && EtatFeuxNuit == LOW){ //Eclairage de nuit
EtatBouton = 2;
}
// Exécution des fonctions selon la valeur de EtatBouton
switch (EtatBouton) {
//Sans éclairage
case 0:
if (EtatClignoDroit == HIGH && EtatClignoGauche == LOW && EtatFrein == LOW){ //Clignotant droit seul
ClignotantDroit();
}
else if (EtatClignoDroit == LOW && EtatClignoGauche == HIGH && EtatFrein == LOW){ //Clignotant gauche seul
ClignotantGauche();
}
else if (EtatClignoDroit == HIGH && EtatClignoGauche == HIGH && EtatFrein == LOW){ //Feux de détresse seuls
do {
FeuxDetresse();
}
while (EtatClignoDroit == HIGH && EtatClignoGauche == HIGH);
}
else if (EtatClignoDroit == LOW && EtatClignoGauche == LOW && EtatFrein == HIGH){ //Freins seuls
FeuxStopON();
}
else if (EtatClignoDroit == HIGH && EtatClignoGauche == LOW && EtatFrein == HIGH){ //Freins et cligno droit
// do {
while (EtatFrein == HIGH) {
ClignotantDroit();
FeuxStopON();
}
// while (EtatFrein == LOW);
}
else if (EtatClignoDroit == LOW && EtatClignoGauche == HIGH && EtatFrein == HIGH){ //Freins et cligno gauche
// do {
while (EtatFrein == HIGH) {
ClignotantGauche();
FeuxStopON();
}
// while (EtatFrein == LOW);
}
else if (EtatClignoDroit == HIGH && EtatClignoGauche == HIGH && EtatFrein == HIGH){ //Freins et Feux détresse
// do {
while (EtatFrein == HIGH) {
ClignotantDroit();
ClignotantGauche();
FeuxStopON();
}
// while (EtatFrein == LOW);
}
// else if (EtatFrein == LOW){
// FeuxStopOFF();
// }
if (EtatFeuxMat = LOW){
FeuxMatON();
}
break;
//Eclairage de jour
case 1:
if (EtatClignoDroit == LOW && EtatClignoGauche == LOW && EtatFrein == LOW){ //Pas de Clignotants
FeuxJourAvantCligno();
// FeuxJourArriereCligno();
Feuxjour12Vcligno();
}
else if (EtatClignoDroit == HIGH && EtatClignoGauche == LOW && EtatFrein == LOW){ //Clignotant droit
ClignotantDroit();
// FeuxJourFixe();
Feuxjour12Vcligno();
}
else if (EtatClignoDroit == LOW && EtatClignoGauche == HIGH && EtatFrein == LOW){ //Clignotant gauche
ClignotantGauche();
// FeuxJourFixe();
Feuxjour12Vcligno();
}
else if (EtatClignoDroit == HIGH && EtatClignoGauche == HIGH && EtatFrein == LOW){ //Feux de détresse
// do {
while (EtatClignoDroit == HIGH && EtatClignoGauche == HIGH) {
FeuxDetresse();
// FeuxJourFixe();
Feuxjour12Vcligno();
}
// while (EtatClignoDroit == HIGH && EtatClignoGauche == HIGH);
}
else if (EtatClignoDroit == LOW && EtatClignoGauche == LOW && EtatFrein == HIGH){ //Freins seuls
// do {
while (EtatFrein == HIGH) {
FeuxJourFixe();
FeuxStopON();
}
// while (EtatFrein == LOW);
}
else if (EtatClignoDroit == HIGH && EtatClignoGauche == LOW && EtatFrein == HIGH){ //Freins et cligno droit
// do {
while (EtatFrein == HIGH) {
ClignotantDroit();
FeuxJourFixe();
FeuxStopON();
}
// while (EtatFrein == LOW);
}
else if (EtatClignoDroit == LOW && EtatClignoGauche == HIGH && EtatFrein == HIGH){ //Freins et cligno gauche
// do {
while (EtatFrein == HIGH) {
ClignotantGauche();
FeuxJourFixe();
FeuxStopON();
}
// while (EtatFrein == LOW);
}
else if (EtatClignoDroit == HIGH && EtatClignoGauche == HIGH && EtatFrein == HIGH){ //Freins et feux de détresse
// do {
while (EtatFrein == HIGH) {
ClignotantDroit();
ClignotantGauche();
FeuxJourFixe();
FeuxStopON();
}
// while (EtatFrein == LOW);
}
else if (EtatFrein == LOW){
Feuxjour12Vcligno();
FeuxStopOFF();
}
if (EtatFeuxMat = LOW){
FeuxMatON();
}
break;
//Eclairage de nuit
case 2:
if (EtatClignoDroit == LOW && EtatClignoGauche == LOW && EtatFrein == LOW){ //Sans frein ni cligno
FeuxNuitON();
}
else if (EtatClignoDroit == HIGH && EtatClignoGauche == LOW && EtatFrein == LOW){ //Clignotant droit
ClignotantDroit();
FeuxNuitON();
}
else if (EtatClignoDroit == LOW && EtatClignoGauche == HIGH && EtatFrein == LOW){ //Clignotant gauche
ClignotantGauche();
FeuxNuitON();
}
else if (EtatClignoDroit == HIGH && EtatClignoGauche == HIGH && EtatFrein == LOW){ //Feux de détresse
// do {
while (EtatClignoDroit == HIGH && EtatClignoGauche == HIGH) {
FeuxDetresse();
FeuxNuitON();
}
// while (EtatClignoDroit == HIGH && EtatClignoGauche == HIGH);
}
else if (EtatClignoDroit == LOW && EtatClignoGauche == LOW && EtatFrein == HIGH){ //Freins seuls
// do {
while (EtatFrein == HIGH){
FeuxJourFixe();
FeuxStopON();
}
// while (EtatFrein == LOW);
}
else if (EtatClignoDroit == HIGH && EtatClignoGauche == LOW && EtatFrein == HIGH){ //Freins et cligno droit
// do {
while (EtatFrein == HIGH){
ClignotantDroit();
FeuxJourFixe();
FeuxStopON();
}
// while (EtatFrein == LOW);
}
else if (EtatClignoDroit == LOW && EtatClignoGauche == HIGH && EtatFrein == HIGH){ //Freins et cligno gauche
// do {
while (EtatFrein == HIGH){
ClignotantGauche();
FeuxJourFixe();
FeuxStopON();
}
// while (EtatFrein == LOW);
}
else if (EtatClignoDroit == HIGH && EtatClignoGauche == HIGH && EtatFrein == HIGH){ //Freins et feux de détresse
// do {
while (EtatFrein == HIGH){
ClignotantDroit();
ClignotantGauche();
FeuxJourFixe();
FeuxStopON();
}
// while (EtatFrein == LOW);
}
else if (EtatFrein == LOW);
FeuxStopOFF();
if (EtatFeuxMat = LOW){
FeuxMatON();
}
break;
}
} |
Partager