Advertisement
Guest User

Untitled

a guest
Jan 28th, 2020
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.60 KB | None | 0 0
  1. #include <ClickButton.h>
  2.  
  3. //Phare
  4.  
  5. const int BP_Phare_pin = A0;
  6. const int Relais_Phare = 12;
  7. bool Phare_etat = false;
  8. bool Relais_Phare_etat = false;
  9. int BP_Phare_etat = 0;
  10.  
  11. ClickButton BP_Phare(BP_Phare_pin, LOW, CLICKBTN_PULLUP);
  12.  
  13. //Klaxon
  14.  
  15. const int BP_Klax_pin = A1;
  16. const int Relais_Klax = 11;
  17. bool Klax_etat = false;
  18. bool Relais_Klax_etat = false;
  19.  
  20. ClickButton BP_Klax(BP_Klax_pin, LOW, CLICKBTN_PULLUP);
  21.  
  22. //Frein
  23.  
  24. const int BP_Frein_pin = A4;
  25. const int Relais_Frein = 8;
  26. bool Frein_etat = false;
  27. bool Relais_Frein_etat = false;
  28.  
  29. ClickButton BP_Frein(BP_Frein_pin, LOW, CLICKBTN_PULLUP);
  30.  
  31. //Cligno droit
  32.  
  33. const int BP_cligno_D_pin = A2;
  34. const int Relais_cligo_D = 10;
  35. bool cligno_D_etat = false;
  36. bool Relais_cligno_D_etat = false;
  37. int BP_cligno_D_etat = 0;
  38. bool Led_cligno_D_etat = false;
  39.  
  40. ClickButton BP_cligno_D(BP_cligno_D_pin, LOW, CLICKBTN_PULLUP);
  41.  
  42. //Cligno gauche
  43.  
  44. const int BP_cligno_G_pin = A3;
  45. const int Relais_cligo_G = 9;
  46. bool cligno_G_etat = false;
  47. bool Relais_cligno_G_etat = false;
  48. int BP_cligno_G_etat = 0;
  49. int Led_cligno_G_etat = 0;
  50.  
  51. ClickButton BP_cligno_G(BP_cligno_G_pin, LOW, CLICKBTN_PULLUP);
  52.  
  53.  
  54. void setup()
  55. {
  56. pinMode(Relais_Klax,OUTPUT);
  57. pinMode(Relais_Phare,OUTPUT);
  58. pinMode(Relais_Frein,OUTPUT);
  59. pinMode(Relais_cligo_D,OUTPUT);
  60. pinMode(Relais_cligo_G,OUTPUT);
  61.  
  62. BP_Phare.debounceTime = 20;
  63. BP_Phare.multiclickTime = 250;
  64. BP_Phare.longClickTime = 500;
  65. BP_Klax.debounceTime = 20;
  66. BP_Frein.debounceTime = 20;
  67. BP_cligno_D.debounceTime = 20;
  68. BP_cligno_D.longClickTime = 500;
  69. BP_cligno_G.debounceTime = 20;
  70. BP_cligno_G.longClickTime = 500;
  71. }
  72.  
  73. void loop()
  74. {
  75. Lecture_BP();
  76.  
  77. //Klaxon
  78. if (Relais_Klax_etat == true){Klax_on();}
  79. else {Klax_off();}
  80.  
  81. //Phare
  82. if (BP_Phare.clicks == 1 && Phare_etat == true){Phare_off();}
  83. if (BP_Phare.clicks == -1 && Phare_etat == false){Phare_on();}
  84. if (BP_Phare.clicks == 1 && Phare_etat == false){Appel_Phare_on();}
  85. if (BP_Phare.clicks == 2 && Phare_etat == false){Appel_Phare_2x_on();}
  86.  
  87. //Frein
  88. if (Relais_Frein_etat == true){Frein_on();}
  89. else {Frein_off();}
  90.  
  91. //Cligotants
  92. if (BP_cligno_D.clicks == 1 && cligno_D_etat == false)
  93. {
  94. clignotement_droit_on ();
  95. }
  96. if (BP_cligno_D.clicks == 1 && cligno_D_etat == true)
  97. {
  98. clignotement_droit_off ();
  99. }
  100.  
  101. if (BP_cligno_G.clicks == 1 && cligno_G_etat == false)
  102. {
  103. clignotement_gauche_on ();
  104. }
  105. if (BP_cligno_G.clicks == 1 && cligno_G_etat == true)
  106. {
  107. clignotement_gauche_off ();
  108. }
  109. }
  110.  
  111. //LECTURE DES BOUTTONS
  112. void Lecture_BP()
  113. {
  114.  
  115. //Lecture du bouton klaxon
  116. BP_Klax.Update();
  117. if (BP_Klax.depressed == true)
  118. {
  119. Relais_Klax_etat = true;
  120. }
  121. else Relais_Klax_etat = false;
  122.  
  123. //Lecture du bouton Phare
  124. BP_Phare.Update();
  125.  
  126. if (BP_Phare.clicks != 0)
  127. {
  128. BP_Phare_etat = BP_Phare.clicks;
  129. }
  130.  
  131. //Lecture du bouton Frein
  132. BP_Frein.Update();
  133. if (BP_Frein.depressed == true)
  134. {
  135. Relais_Frein_etat = true;
  136. }
  137. else Relais_Frein_etat = false;
  138.  
  139. //Lecture du bouton clignotant gauche
  140. BP_cligno_G.Update();
  141.  
  142. if (BP_cligno_G.clicks != 0)
  143. {
  144. BP_cligno_G_etat = BP_cligno_G.clicks;
  145. }
  146.  
  147. //Lecture du bouton clignotant droit
  148. BP_cligno_D.Update();
  149.  
  150. if (BP_cligno_D.clicks != 0)
  151. {
  152. BP_cligno_D_etat = BP_cligno_D.clicks;
  153. }
  154.  
  155. }
  156.  
  157. //KLAXON
  158. void Klax_on()
  159. {
  160. digitalWrite(Relais_Klax,HIGH);
  161. }
  162. void Klax_off()
  163. {
  164. digitalWrite(Relais_Klax,LOW);
  165. }
  166.  
  167.  
  168. // PLEIN PHARE
  169. void Phare_on()
  170. {
  171. digitalWrite(Relais_Phare,HIGH);
  172. Phare_etat = true;
  173. }
  174. void Phare_off()
  175. {
  176. digitalWrite(Relais_Phare,LOW);
  177. Phare_etat = false;
  178. }
  179. void Appel_Phare_on()
  180. {
  181. digitalWrite(Relais_Phare,HIGH);
  182. delay (30);
  183. digitalWrite(Relais_Phare,LOW);
  184. Phare_etat = false;
  185. }
  186. void Appel_Phare_2x_on()
  187. {
  188. digitalWrite(Relais_Phare,HIGH);
  189. delay (30);
  190. digitalWrite(Relais_Phare,LOW);
  191. delay (100);
  192. digitalWrite(Relais_Phare,HIGH);
  193. delay (30);
  194. digitalWrite(Relais_Phare,LOW);
  195. Phare_etat = false;
  196. }
  197.  
  198.  
  199. // Frein
  200. void Frein_on()
  201. {
  202. digitalWrite(Relais_Frein,HIGH);
  203. }
  204. void Frein_off()
  205. {
  206. digitalWrite(Relais_Frein,LOW);
  207. }
  208.  
  209. // clignotants
  210.  
  211. void clignotement_droit_on ()
  212. {
  213. digitalWrite(Relais_cligo_D, millis() / 500 %2);
  214. cligno_D_etat = true;
  215. }
  216.  
  217. void clignotement_droit_off ()
  218. {
  219. digitalWrite(Relais_cligo_D,LOW);
  220. cligno_D_etat = false;
  221. }
  222.  
  223. void clignotement_gauche_on ()
  224. {
  225. digitalWrite(Relais_cligo_G, millis() / 500 %2);
  226. cligno_G_etat = true;
  227. }
  228.  
  229. void clignotement_gauche_off ()
  230. {
  231. digitalWrite(Relais_cligo_G,LOW);
  232. cligno_G_etat = false;
  233. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement