Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <ClickButton.h>
- //Phare
- const int BP_Phare_pin = A0;
- const int Relais_Phare = 12;
- bool Phare_etat = false;
- bool Relais_Phare_etat = false;
- int BP_Phare_etat = 0;
- ClickButton BP_Phare(BP_Phare_pin, LOW, CLICKBTN_PULLUP);
- //Klaxon
- const int BP_Klax_pin = A1;
- const int Relais_Klax = 11;
- bool Klax_etat = false;
- bool Relais_Klax_etat = false;
- ClickButton BP_Klax(BP_Klax_pin, LOW, CLICKBTN_PULLUP);
- //Frein
- const int BP_Frein_pin = A4;
- const int Relais_Frein = 8;
- bool Frein_etat = false;
- bool Relais_Frein_etat = false;
- ClickButton BP_Frein(BP_Frein_pin, LOW, CLICKBTN_PULLUP);
- //Cligno droit
- const int BP_cligno_D_pin = A2;
- const int Relais_cligo_D = 10;
- bool cligno_D_etat = false;
- bool Relais_cligno_D_etat = false;
- int BP_cligno_D_etat = 0;
- bool Led_cligno_D_etat = false;
- ClickButton BP_cligno_D(BP_cligno_D_pin, LOW, CLICKBTN_PULLUP);
- //Cligno gauche
- const int BP_cligno_G_pin = A3;
- const int Relais_cligo_G = 9;
- bool cligno_G_etat = false;
- bool Relais_cligno_G_etat = false;
- int BP_cligno_G_etat = 0;
- int Led_cligno_G_etat = 0;
- ClickButton BP_cligno_G(BP_cligno_G_pin, LOW, CLICKBTN_PULLUP);
- void setup()
- {
- pinMode(Relais_Klax,OUTPUT);
- pinMode(Relais_Phare,OUTPUT);
- pinMode(Relais_Frein,OUTPUT);
- pinMode(Relais_cligo_D,OUTPUT);
- pinMode(Relais_cligo_G,OUTPUT);
- BP_Phare.debounceTime = 20;
- BP_Phare.multiclickTime = 250;
- BP_Phare.longClickTime = 500;
- BP_Klax.debounceTime = 20;
- BP_Frein.debounceTime = 20;
- BP_cligno_D.debounceTime = 20;
- BP_cligno_D.longClickTime = 500;
- BP_cligno_G.debounceTime = 20;
- BP_cligno_G.longClickTime = 500;
- }
- void loop()
- {
- Lecture_BP();
- //Klaxon
- if (Relais_Klax_etat == true){Klax_on();}
- else {Klax_off();}
- //Phare
- if (BP_Phare.clicks == 1 && Phare_etat == true){Phare_off();}
- if (BP_Phare.clicks == -1 && Phare_etat == false){Phare_on();}
- if (BP_Phare.clicks == 1 && Phare_etat == false){Appel_Phare_on();}
- if (BP_Phare.clicks == 2 && Phare_etat == false){Appel_Phare_2x_on();}
- //Frein
- if (Relais_Frein_etat == true){Frein_on();}
- else {Frein_off();}
- //Cligotants
- if (BP_cligno_D.clicks == 1 && cligno_D_etat == false)
- {
- clignotement_droit_on ();
- }
- if (BP_cligno_D.clicks == 1 && cligno_D_etat == true)
- {
- clignotement_droit_off ();
- }
- if (BP_cligno_G.clicks == 1 && cligno_G_etat == false)
- {
- clignotement_gauche_on ();
- }
- if (BP_cligno_G.clicks == 1 && cligno_G_etat == true)
- {
- clignotement_gauche_off ();
- }
- }
- //LECTURE DES BOUTTONS
- void Lecture_BP()
- {
- //Lecture du bouton klaxon
- BP_Klax.Update();
- if (BP_Klax.depressed == true)
- {
- Relais_Klax_etat = true;
- }
- else Relais_Klax_etat = false;
- //Lecture du bouton Phare
- BP_Phare.Update();
- if (BP_Phare.clicks != 0)
- {
- BP_Phare_etat = BP_Phare.clicks;
- }
- //Lecture du bouton Frein
- BP_Frein.Update();
- if (BP_Frein.depressed == true)
- {
- Relais_Frein_etat = true;
- }
- else Relais_Frein_etat = false;
- //Lecture du bouton clignotant gauche
- BP_cligno_G.Update();
- if (BP_cligno_G.clicks != 0)
- {
- BP_cligno_G_etat = BP_cligno_G.clicks;
- }
- //Lecture du bouton clignotant droit
- BP_cligno_D.Update();
- if (BP_cligno_D.clicks != 0)
- {
- BP_cligno_D_etat = BP_cligno_D.clicks;
- }
- }
- //KLAXON
- void Klax_on()
- {
- digitalWrite(Relais_Klax,HIGH);
- }
- void Klax_off()
- {
- digitalWrite(Relais_Klax,LOW);
- }
- // PLEIN PHARE
- void Phare_on()
- {
- digitalWrite(Relais_Phare,HIGH);
- Phare_etat = true;
- }
- void Phare_off()
- {
- digitalWrite(Relais_Phare,LOW);
- Phare_etat = false;
- }
- void Appel_Phare_on()
- {
- digitalWrite(Relais_Phare,HIGH);
- delay (30);
- digitalWrite(Relais_Phare,LOW);
- Phare_etat = false;
- }
- void Appel_Phare_2x_on()
- {
- digitalWrite(Relais_Phare,HIGH);
- delay (30);
- digitalWrite(Relais_Phare,LOW);
- delay (100);
- digitalWrite(Relais_Phare,HIGH);
- delay (30);
- digitalWrite(Relais_Phare,LOW);
- Phare_etat = false;
- }
- // Frein
- void Frein_on()
- {
- digitalWrite(Relais_Frein,HIGH);
- }
- void Frein_off()
- {
- digitalWrite(Relais_Frein,LOW);
- }
- // clignotants
- void clignotement_droit_on ()
- {
- digitalWrite(Relais_cligo_D, millis() / 500 %2);
- cligno_D_etat = true;
- }
- void clignotement_droit_off ()
- {
- digitalWrite(Relais_cligo_D,LOW);
- cligno_D_etat = false;
- }
- void clignotement_gauche_on ()
- {
- digitalWrite(Relais_cligo_G, millis() / 500 %2);
- cligno_G_etat = true;
- }
- void clignotement_gauche_off ()
- {
- digitalWrite(Relais_cligo_G,LOW);
- cligno_G_etat = false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement