Advertisement
Guest User

Untitled

a guest
Apr 20th, 2023
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.60 KB | None | 0 0
  1.  
  2.  
  3. #include "Arduino.h"
  4. #include <FastLED.h>
  5.  
  6. #define LED_PIN 3 //LED Strip Signal Connection
  7. #define BrakeSignal 5 //Brake Signal Connection
  8. #define LeftSignal 7 //Left Blinker Signal Connection
  9. #define RightSignal 9 //Right Blinker Signal Connection
  10. #define ReverseSignal 11 //Reverse Signal Connection
  11.  
  12. #define NUM_LEDS 288 //Total no of LEDs in the LED strip
  13. #define BlinkerLEDs 68 //No of LEDs for Left/Right Blinker
  14.  
  15.  
  16. int BlinkerSpeed = 0; //Turn Signal Running LED Speed. Adjust this to match with your vehicle turn signal speed.
  17. int BlinkerOffDelay = 100; //Turn Signal Off time. Adjust this to match with your vehicle turn signal speed.
  18.  
  19. int StartupSpeed = 4;
  20.  
  21. CRGB leds[NUM_LEDS];
  22.  
  23.  
  24. void setup()
  25. {
  26. FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS);
  27. pinMode(BrakeSignal, INPUT);
  28. pinMode(LeftSignal, INPUT);
  29. pinMode(RightSignal, INPUT);
  30. pinMode(ReverseSignal, INPUT);
  31.  
  32.  
  33. for (int i = 0; i < (NUM_LEDS/2); i++)
  34. {
  35. leds[i] = CRGB(30, 0, 0);
  36. leds[i-1] = CRGB(0, 0, 0);
  37. leds[(NUM_LEDS-1)-i] = CRGB(30, 0, 0);
  38. leds[(NUM_LEDS)-i] = CRGB(0, 0, 0);
  39. FastLED.show();
  40. delay (StartupSpeed);
  41. }
  42.  
  43. for (int j = ((NUM_LEDS/2)-1); j >= 0; j--)
  44. {
  45. leds[j] = CRGB(30, 0, 0);
  46. leds[(NUM_LEDS/2-1)+((NUM_LEDS/2)-j)] = CRGB(30, 0, 0);
  47. FastLED.show();
  48. delay (StartupSpeed);
  49. }
  50.  
  51. for (int j = ((NUM_LEDS/2)-1); j >= 0; j--)
  52. {
  53. leds[j] = CRGB(255, 0, 0);
  54. leds[(NUM_LEDS/2-1)+((NUM_LEDS/2)-j)] = CRGB(255, 0, 0);
  55. FastLED.show();
  56. delay (StartupSpeed);
  57. }
  58.  
  59. for (int j = 255; j >= 60; j--)
  60. {
  61. for (int i = 0; i < NUM_LEDS; i++)
  62. {
  63. leds[i] = CRGB(j, 0, 0);
  64. }
  65. FastLED.show();
  66. delay (5);
  67. }
  68. }
  69.  
  70.  
  71. void loop()
  72. {
  73. if((digitalRead(ReverseSignal)==1)&&(digitalRead(BrakeSignal)==0)) //Reverse Light
  74. {
  75. Reverse();
  76. }
  77.  
  78. if((digitalRead(ReverseSignal)==1)&&(digitalRead(BrakeSignal)==1)) //Brake Light
  79. {
  80. Reverse();
  81. }
  82.  
  83. if(digitalRead(ReverseSignal)==0)
  84. {
  85. if((digitalRead(LeftSignal)==0)&&(digitalRead(RightSignal)==0)&&(digitalRead(BrakeSignal)==0)) //Park Light
  86. {
  87. ParkFull();
  88. }
  89.  
  90. if((digitalRead(BrakeSignal)==1)&&(digitalRead(LeftSignal)==0)&&(digitalRead(RightSignal)==0)) //Brake Light
  91. {
  92. BrakeFull();
  93. }
  94.  
  95. if((digitalRead(LeftSignal)==1)&&(digitalRead(RightSignal)==0)&&(digitalRead(BrakeSignal)==0)) //Left Blinker
  96. {
  97. LeftDim();
  98. RightLit();
  99. LeftBlinker();
  100. LeftDim();
  101. delay (BlinkerOffDelay);
  102. }
  103.  
  104. if((digitalRead(RightSignal)==1)&&(digitalRead(LeftSignal)==0)&&(digitalRead(BrakeSignal)==0)) //Right Blinker
  105. {
  106. RightDim();
  107. LeftLit();
  108. RightBlinker();
  109. RightDim();
  110. delay (BlinkerOffDelay);
  111. }
  112.  
  113. if((digitalRead(LeftSignal)==1)&&(digitalRead(RightSignal)==0)&&(digitalRead(BrakeSignal)==1)) //Left Blinker & Brake
  114. {
  115. LeftDim();
  116. RightFull();
  117. LeftBlinker();
  118. LeftDim();
  119. delay (BlinkerOffDelay);
  120. }
  121.  
  122. if((digitalRead(RightSignal)==1)&&(digitalRead(LeftSignal)==0)&&(digitalRead(BrakeSignal)==1)) //Right Blinker & Brake
  123. {
  124. RightDim();
  125. LeftFull();
  126. RightBlinker();
  127. RightDim();
  128. delay (BlinkerOffDelay);
  129. }
  130.  
  131. if((digitalRead(LeftSignal)==1)&&(digitalRead(RightSignal)==1)&&(digitalRead(BrakeSignal)==0)) //Dual Blinker / Hazard
  132. {
  133. LeftDim();
  134. RightDim();
  135. ParkMiddle();
  136. DualBlinker();
  137. LeftDim();
  138. RightDim();
  139. delay (BlinkerOffDelay);
  140. }
  141.  
  142. if((digitalRead(LeftSignal)==1)&&(digitalRead(RightSignal)==1)&&(digitalRead(BrakeSignal)==1)) //Dual Blinker / Hazard + Brake
  143. {
  144. LeftDim();
  145. RightDim();
  146. BrakeMiddle();
  147. DualBlinker();
  148. LeftDim();
  149. RightDim();
  150. delay (BlinkerOffDelay);
  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. void Reverse()
  183. {
  184. for (int i = 0; i < NUM_LEDS; i++)
  185. {
  186. leds[i] = CRGB(255, 255, 255);
  187. }
  188. FastLED.show();
  189. }
  190.  
  191. void BrakeFull()
  192. {
  193. for (int i = 0; i < NUM_LEDS; i++)
  194. {
  195. leds[i] = CRGB(255, 0, 0);
  196. }
  197. FastLED.show();
  198. }
  199.  
  200. void BrakeMiddle()
  201. {
  202. for (int i = BlinkerLEDs; i < (NUM_LEDS - BlinkerLEDs); i++)
  203. {
  204. leds[i] = CRGB(255, 0, 0);
  205. }
  206. FastLED.show();
  207. }
  208.  
  209. void ParkFull()
  210. {
  211. for (int i = 0; i < NUM_LEDS; i++)
  212. {
  213. leds[i] = CRGB(60, 0, 0);
  214. }
  215. FastLED.show();
  216. }
  217.  
  218. void ParkMiddle()
  219. {
  220. for (int i = BlinkerLEDs; i < (NUM_LEDS - BlinkerLEDs); i++)
  221. {
  222. leds[i] = CRGB(60, 0, 0);
  223. }
  224. FastLED.show();
  225. }
  226.  
  227. void LeftBlinker()
  228. {
  229. for (int i = (BlinkerLEDs-1); i >= 0; i--)
  230. {
  231. leds[i] = CRGB(255, 165, 0);
  232. FastLED.show();
  233. delay (BlinkerSpeed);
  234. }
  235. }
  236.  
  237. void LeftDim()
  238. {
  239. for (int i = 0; i < BlinkerLEDs; i++)
  240. {
  241. leds[i] = CRGB(0, 0, 0);
  242. }
  243. FastLED.show();
  244. }
  245.  
  246. void LeftLit()
  247. {
  248. for (int i = 0; i < (NUM_LEDS - BlinkerLEDs); i++)
  249. {
  250. leds[i] = CRGB(75, 0, 0);
  251. }
  252. FastLED.show();
  253. }
  254.  
  255. void LeftFull()
  256. {
  257. for (int i = 0; i < (NUM_LEDS - BlinkerLEDs); i++)
  258. {
  259. leds[i] = CRGB(255, 0, 0);
  260. }
  261. FastLED.show();
  262. }
  263.  
  264. void RightBlinker()
  265. {
  266. for (int i = (NUM_LEDS - BlinkerLEDs); i < NUM_LEDS; i++)
  267. {
  268. leds[i] = CRGB(255, 165, 0);
  269. FastLED.show();
  270. delay (BlinkerSpeed);
  271. }
  272. }
  273.  
  274. void RightDim()
  275. {
  276. for (int i = (NUM_LEDS - BlinkerLEDs); i < NUM_LEDS; i++)
  277. {
  278. leds[i] = CRGB(0, 0, 0);
  279. }
  280. FastLED.show();
  281. }
  282.  
  283. void RightLit()
  284. {
  285. for (int i = BlinkerLEDs; i < NUM_LEDS; i++)
  286. {
  287. leds[i] = CRGB(75, 0, 0);
  288. }
  289. FastLED.show();
  290. }
  291.  
  292. void RightFull()
  293. {
  294. for (int i = BlinkerLEDs; i < NUM_LEDS; i++)
  295. {
  296. leds[i] = CRGB(255, 0, 0);
  297. }
  298. FastLED.show();
  299. }
  300.  
  301. void DualBlinker()
  302. {
  303. for (int i = (BlinkerLEDs-1); i >= 0; i--)
  304. {
  305. leds[i] = CRGB(255, 165, 0);
  306. leds[NUM_LEDS-1-i] = CRGB(255, 165, 0);
  307. FastLED.show();
  308. delay (BlinkerSpeed);
  309. }
  310. }
  311.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement