Jeremy from Pololu suggested I join up and post this up so here it goes!
First off, I am relatively new to coding. I am an avionics guy by trade and understand board level components, but had not touched a micro-controller up until a few months ago when I was assigned as part of a design team to develop a smart battery charger/tester for emergency light batteries on an aircraft. Our design was using an Arduino Mega. That set me off into the “self education” mode. So that being said, I have been trying to apply some of what I am learning to something a little more fun.
I am working on a flasher that will control multiple strobe pods. My second job includes sales and installation of off road vehicle accessories so I want to do something useful for safety lights for off road trucks. What I have running so far is pretty simple. It’s strobing two 18W LED PODS. I’m using the Arduino to fire two TIP32’s to control the strobes. I admit that I had to grab the initial code from James at CMIYC because I am having some difficulty grasping the milis() function.
Future plans that I want to develop include adding two to four more outputs, having selectable modes from continuous on, to a chasing pattern that would fire the strobes sequentially, and a separate project that would control just a single light bar. (Higher amp draw so looking at doing that with a STP40NF10L MOSFET. I’ll also be moving this to the 32U4 so I can make the final package much smaller.
Feel free to offer up any suggestions, criticism, etc.
Here is a quick video of what I have thus far:
https://flic.kr/p/qoctQQ
And the code that I used to get started:
10. // English for which LED to Strobe
11. #define RED 0x0
12. #define BLUE 0x1
13.
14. // Variable to track which LED is on
15. byte whichLED = RED;
16.
17. // Where are the LEDs connected?
18. const int LED_Red = 7;
19. const int LED_Blue = 11;
20.
21. // State variables for the LEDs
22. byte Red_State = LOW;
23. byte Blue_State = LOW;
24.
25. // Some delay values to change flashing behavior
26. unsigned long switchDelay = 250;
27. unsigned long strobeDelay = 50;
28.
29. // Seed the initial wait for the strobe effect
30. unsigned long strobeWait = strobeDelay;
31.
32. // Variable to see when we should swtich LEDs
33. unsigned long waitUntilSwitch = switchDelay; // seed initial wait
34.
35.
36. void setup() {
37. pinMode(LED_Red, OUTPUT);
38. pinMode(LED_Blue, OUTPUT);
39. }
40.
41. void loop() {
42. digitalWrite(LED_Red, Red_State); // each iteration of loop() will set the IO pins,
43. digitalWrite(LED_Blue, Blue_State); // even if they don't change, that's okay
44.
45. // Toggle back and forth between the two LEDs
46. if ((long)(millis() - waitUntilSwitch)>=0) {
47. // time is up!
48. Red_State = LOW;
49. Blue_State = LOW;
50. whichLED = !whichLED; // toggle LED to strobe
51. waitUntilSwitch += switchDelay;
52. }
53.
54. // Create the stobing effect
55. if ((long)(millis() - strobeWait)>=0) {
56. if (whichLED == RED)
57. Red_State = !Red_State;
58. if (whichLED == BLUE)
59. Blue_State = !Blue_State;
60. strobeWait += strobeDelay;
61. }
62. }