skizziks_53

ebike_light_controller_v1

Dec 6th, 2018
343
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 24.09 KB | None | 0 0
  1. /*
  2.    5 December 2018
  3.    reddit e-bike lights controller version 1.0 (headlights, blinkers and brake light)
  4.    reddit: Dougcim53
  5.    Board: Arduino uno/nano
  6.    No external / non-standard libraries used
  7. */
  8.  
  9. // Troubleshooting message switches ########################################
  10. bool print_function_messages = false; // set to false to turn off all the function serial messages. This one will send a lot of messages if set to true.
  11.  
  12. // Printing serial messages is nice when building and testing, but they cause time delays you may not want in the final version.
  13. // This variable is a switch that allows or prevents all of the function serial messages from printing.
  14.  
  15. bool print_blinker_messages = true; // This is the same thing, but just for the blinker on/off changes.
  16. bool print_headlight_1_messages = true; // And these are for the other outputs.
  17. bool print_headlight_2_messages = true;
  18. bool print_brake_light_messages = true;
  19.  
  20. bool print_joystick_leftRight_messages = true; // Might as well do the control inputs also, since the whole sketch is still pretty small.
  21. bool print_joystick_upDown_messages = true;
  22. bool print_blinker_cancel_button_messages = true;
  23. bool print_brake_input_messages = true;
  24.  
  25.  
  26. // I/O pin setup ####################################################
  27. int joystick_leftRight_axis = A0; // analog input for joystick
  28. int joystick_upDown_axis = A1; // analog input for joystick
  29.  
  30. int brake_trigger_pin = 3; // digital input, active = high
  31. int blinker_cancel_pin = 4; // digital input, active = high
  32.  
  33. int headlight_1_pin = 9; // digital output pin
  34. int headlight_2_pin = 8; // digital output pin
  35. int blinker_left_pin = 12; // digital output pin
  36. int blinker_right_pin = 10; // digital output pin
  37. int brake_light_pin = 11; // digital output pin
  38.  
  39.  
  40. // Control timer setup ###################################################
  41. // To prevent accidental activation, the buttons/joystick must be pressed for at least two consecutive cycles of whatever their time intervals are.
  42.  
  43. int headlight_1_activation_time = 500; // 500 time value is in milliseconds. This is the time to press the joystick UP to turn on headlight #1.
  44. int headlight_2_activation_time = 750; // 1000 time value is in milliseconds. This is the time to press the joystick UP to turn on headlight #2.
  45. // Note that the headlight #2 value must be greater than #1.
  46. int headlight_turn_off_time = 1000; // Milliseconds value. This is the time to pull the joystick down to turn off the headlights/running lights.
  47.  
  48. int blinker_activation_interval = 500; // 500 time value is milliseconds. This is how long to hold the joystick left or right to turn that blinker direction on.
  49. int blinker_on_time = 300; // 300 time value is milliseconds. This is the time that the blinker LED will be 'on'.
  50. int blinker_off_time = 150; // 150 time value is in milliseconds. This is the time that the blinker LED will be 'off'.
  51. int blinker_cancel_button_time_interval = 250; // This is the time to hold the blinker cancel button to turn off the blinkers.
  52.  
  53. int brake_light_low_value = 128; // This is a PWM value. This is the value of the brake light, when NOT active, but when either of the headlights are on.
  54. int brake_light_high_value = 255; // This is a PWM value. This is the active value of the brake light, if the leadlights are on or not.
  55. int brake_input_check_interval = 100; // This is the time interval to check the brake input pin.
  56.  
  57.  
  58. // Joystick threshold values ###################################################
  59. // These assume that the analog pin value is used directly (0 - 1023)
  60. int joystick_up_active_value = 800;
  61. int joystick_down_active_value = 200;
  62. // You may need to flip these values around, depending on how the joystick is wired.
  63. // Also the functions reading the joystick values may need the comparator signs changed.
  64.  
  65. int joystick_left_active_value = 200;
  66. int joystick_right_active_value = 800;
  67. // You may need to flip these values around, depending on how the joystick is wired.
  68. // Also the functions reading the joystick values may need the comparator signs changed.
  69.  
  70.  
  71. // Other assorted variables ###############################################
  72. int blinker_left_state = 0; // 0 = off, 1 = on
  73. int blinker_left_LED_state = 0; // This represents if the blinker pin is off or on.
  74. int blinker_left_trigger_count = 0; // This must reach 2 for the blinker to turn on.
  75.  
  76. int blinker_right_state = 0; // 0 = off, 1 = on
  77. int blinker_right_LED_state = 0; // This represents if the blinker pin is off or on.
  78. int blinker_right_trigger_count = 0; // This must reach 2 for the blinker to turn on.
  79.  
  80. int headlight_1_state = 0; // 0 = off, 1 = on
  81. int headlight_1_trigger_count = 0;
  82.  
  83. int headlight_2_state = 0; // 0 = off, 1 = on
  84. int headlight_2_trigger_count = 0;
  85.  
  86. int headlights_off_trigger_count = 0;
  87. int blinkers_off_trigger_count = 0;
  88.  
  89. int brake_light_state = 0; // 0 = off, 1 = on
  90. int brake_light_mode = 1; // 1 = low, 2 = high
  91.  
  92. unsigned long brake_control_begin_time = 0; // These are used to time the control checks for the brake input button.
  93. unsigned long brake_control_current_time = 0;
  94.  
  95. unsigned long blinker_cancel_control_begin_time = 0; // These are used to time the control checks for the blinker cancel button.
  96. unsigned long blinker_cancel_control_current_time = 0;
  97.  
  98. unsigned long headlight_1_control_begin_time = 0; // These are used to time the control that turns headlight 1 on and off.
  99. unsigned long headlight_1_control_current_time = 0;
  100.  
  101. unsigned long headlight_2_control_begin_time = 0; // These are used to time the control that turns headlight 2 on and off.
  102. unsigned long headlight_2_control_current_time = 0;
  103.  
  104. unsigned long blinker_control_begin_time = 0; // These are used to time the control that turns the blinkers on and off.
  105. unsigned long blinker_control_current_time = 0;
  106.  
  107. unsigned long blinker_blink_begin_time = 0; // These are used to time the intervals that the blinkers turn on and off, when activated.
  108. unsigned long blinker_blink_current_time = 0;
  109. unsigned long blinker_interval_time = 0;
  110.  
  111.  
  112.  
  113. // ##################################################################################
  114.  
  115. void setup() {
  116.   Serial.begin(9600);
  117.  
  118.   //pinMode(joystick_leftRight_axis, INPUT);
  119.   //pinMode(joystick_upDown_axis, INPUT);
  120.   // With the Arduino IDE and boards, you don't need to set the pinMode for pins that are used for analogRead.
  121.   // IIRC it is because the pins are switched to input during runtime by default, since analogRead can only be performed on an input pin anyway.
  122.   // There is info about the matter online, if you care to read futher.
  123.   // One example of many ----> http://forum.arduino.cc/index.php?topic=281728.0
  124.  
  125.   pinMode(blinker_right_pin, OUTPUT);
  126.   pinMode(blinker_left_pin, OUTPUT);
  127.  
  128.   pinMode(brake_trigger_pin, INPUT);
  129.   pinMode(brake_light_pin, OUTPUT);
  130.  
  131.   pinMode(headlight_2_pin, OUTPUT);
  132.   pinMode(headlight_1_pin, OUTPUT);
  133.  
  134.   if (print_function_messages == true) {
  135.     Serial.println("exiting setup()");
  136.     // If you are using serial messages anyway,
  137.     // it is good to have a serial message when leaving the setup() function.
  138.   }
  139. } // end of setup() function
  140.  
  141.  
  142.  
  143. void loop() {
  144.  
  145.   check_joystick_leftRight_value();
  146.   check_headlight_1_control_value();
  147.   check_headlight_2_control_value();
  148.   check_brake_input_value();
  149.   check_blinker_cancel_button_value();
  150.   check_blinker_state();
  151.  
  152. } // end of main loop
  153.  
  154.  
  155.  
  156. void check_joystick_leftRight_value() {
  157.   if (print_function_messages == true) {
  158.     Serial.println("check_joystick_leftRight_value() called");
  159.   }
  160.   // This function checks the joystick left-right value and turns the same-direction blinker on if it has been held for 2 cycles.
  161.   blinker_control_current_time = millis();
  162.   if (blinker_control_current_time > blinker_control_begin_time) {
  163.     if (blinker_control_current_time >= (blinker_control_begin_time + blinker_activation_interval)) {
  164.       int leftRightValue = analogRead(joystick_leftRight_axis);
  165.       // Below turns on the left blinker.
  166.       if (leftRightValue <= joystick_left_active_value) {
  167.         // NOTE: if you flip the joystick values, then you may need to flip the comparator signs above as well.
  168.         // This means the joystick is pushed left.
  169.         if (print_joystick_leftRight_messages == true) {
  170.           Serial.print("left joystick detected: value = ");
  171.           Serial.println(leftRightValue);
  172.         }
  173.         if (blinker_left_state == 0) {
  174.           switch (blinker_left_trigger_count) {
  175.             case 0:
  176.               blinker_left_trigger_count = 1; // increment this trigger count to 1
  177.               blinker_right_trigger_count = 0; // reset the other blinker trigger count.
  178.               break;
  179.             case 1:
  180.               // if the trigger count reaches 2, the left trigger count is reset to zero and the left blinker is turned on here.
  181.               blinker_left_trigger_count = 0;
  182.               start_left_blinker();
  183.               break;
  184.           }
  185.         }
  186.       }
  187.       // Below turns on the right blinker.
  188.       if (leftRightValue >= joystick_right_active_value) {
  189.         // NOTE: if you flip the joystick values, then you may need to flip the comparator signs above as well.
  190.         // This means the joystick is pushed right.
  191.         if (print_joystick_leftRight_messages == true) {
  192.           Serial.print("right joystick detected: value = ");
  193.           Serial.println(leftRightValue);
  194.         }
  195.         if (blinker_right_state == 0) {
  196.           switch (blinker_right_trigger_count) {
  197.             case 0:
  198.               blinker_right_trigger_count = 1; // increment this trigger count to 1
  199.               blinker_left_trigger_count = 0; // reset the other blinker trigger count.
  200.               break;
  201.             case 1:
  202.               // if the trigger count reaches 2, the left trigger count is reset to zero and the left blinker is turned on here.
  203.               blinker_right_trigger_count = 0;
  204.               start_right_blinker();
  205.               break;
  206.           }
  207.         }
  208.       }
  209.     }
  210.   }
  211.   else {
  212.     blinker_control_begin_time = millis();
  213.   }
  214. }
  215.  
  216.  
  217.  
  218. void check_headlight_1_control_value() {
  219.   if (print_function_messages == true) {
  220.     Serial.println("check_headlight_1_control_value() called");
  221.   }
  222.   // All this does is check the joystick at the headlight_1_activation_time interval,
  223.   // and turns on the headlight #1 if the joystick has been held up for 2 complete intervals.
  224.   headlight_1_control_current_time = millis();
  225.   if (headlight_1_control_current_time > headlight_1_control_begin_time) {
  226.     if (headlight_1_control_current_time >= (headlight_1_control_begin_time + headlight_1_activation_time)) {
  227.       int upDownValue = analogRead(joystick_upDown_axis);
  228.       // Below checks the timer to see if headllight 1 should be turned on.
  229.       if (upDownValue >= joystick_up_active_value) {
  230.         if (headlight_1_state == 0) {
  231.           // NOTE: if you flip the joystick values, then you may need to flip the comparator signs above as well.
  232.           // This means the joystick is pushed left.
  233.           switch (headlight_1_trigger_count) {
  234.             case 0:
  235.               headlight_1_trigger_count = 1; // increment this trigger count to 1
  236.               break;
  237.             case 1:
  238.               // if the trigger count reaches 2, the left trigger count is reset to zero and headlight 1 is turned on here.
  239.               headlight_1_trigger_count = 0;
  240.               turn_on_headlight_1();
  241.               set_brake_light_low(); // also turn on the brake light to low
  242.               break;
  243.           }
  244.         }
  245.         if (print_joystick_upDown_messages == true) {
  246.           Serial.print("UP joystick detected: value = ");
  247.           Serial.println(upDownValue);
  248.         }
  249.       }
  250.       // This function is also used to see if the headlights should be turned off.
  251.       // This is done here because the headlight-1 function has its own timing code anyway,
  252.       //     and the headlights-off fuction doesn't really need its own timing code.
  253.       // The headlights-off function just needs to be called periodically, so it shares the same control interval as headlight-1.
  254.       check_headlight_turnOff_value(upDownValue);
  255.  
  256.       headlight_1_control_begin_time = millis();
  257.     }
  258.   }
  259.   else {
  260.     headlight_1_control_begin_time = millis();
  261.   }
  262. }
  263.  
  264.  
  265. void turn_on_headlight_1() {
  266.   // All that this does is turn on headlight #1.
  267.   if (print_headlight_1_messages == true) {
  268.     Serial.println("headlight 1 turning on");
  269.   }
  270.   headlight_1_state = 1;
  271.   digitalWrite(headlight_1_pin, headlight_1_state);
  272. }
  273.  
  274.  
  275. void turn_off_headlight_1() {
  276.   // All that this does is turn off headlight #1.
  277.   if (print_headlight_1_messages == true) {
  278.     Serial.println("headlight 1 turning off");
  279.   }
  280.   headlight_1_state = 0;
  281.   digitalWrite(headlight_1_pin, headlight_1_state);
  282. }
  283.  
  284.  
  285. void check_headlight_2_control_value() {
  286.   if (print_function_messages == true) {
  287.     Serial.println("check_headlight_2_control_value() called");
  288.   }
  289.   // This function turns on headlight #2, if the joystick has been held up long enough.
  290.   headlight_2_control_current_time = millis();
  291.   if (headlight_2_control_current_time > headlight_2_control_begin_time) {
  292.     if (headlight_2_control_current_time >= (headlight_2_control_begin_time + headlight_2_activation_time)) {
  293.       int upDownValue = analogRead(joystick_upDown_axis);
  294.       if (headlight_2_state == 0) {
  295.         if (upDownValue >= joystick_up_active_value) {
  296.           // NOTE: if you flip the joystick values, then you may need to flip the comparator signs above as well.
  297.           // This means the joystick is pushed left.
  298.           switch (headlight_2_trigger_count) {
  299.             case 0:
  300.               headlight_2_trigger_count = 1; // increment this trigger count to 1
  301.               break;
  302.             case 1:
  303.               // if the trigger count reaches 2, the left trigger count is reset to zero and headlight 1 is turned on here.
  304.               headlight_2_trigger_count = 0;
  305.               turn_on_headlight_2();
  306.               set_brake_light_low(); // also turn on the brake light to low (it should already be on from headlight #1 turning on, but anyway)
  307.               break;
  308.           }
  309.         }
  310.       }
  311.       headlight_2_control_begin_time = millis();
  312.     }
  313.   }
  314.   else {
  315.     headlight_2_control_begin_time = millis();
  316.   }
  317. }
  318.  
  319.  
  320. void turn_on_headlight_2() {
  321.   // All that this does is turn on headlight #2.
  322.   if (print_headlight_2_messages == true) {
  323.     Serial.println("headlight 2 turning on");
  324.   }
  325.   headlight_2_state = 1;
  326.   digitalWrite(headlight_2_pin, headlight_2_state);
  327. }
  328.  
  329.  
  330. void turn_off_headlight_2() {
  331.   // All that this does is turn off headlight #2.
  332.   if (print_headlight_2_messages == true) {
  333.     Serial.println("headlight 2 turning off");
  334.   }
  335.   headlight_2_state = 0;
  336.   digitalWrite(headlight_2_pin, headlight_2_state);
  337. }
  338.  
  339.  
  340. void check_headlight_turnOff_value(int upDownValue) {
  341.   if (print_function_messages == true) {
  342.     Serial.println("check_headlight_turnOff_value(int) called");
  343.   }
  344.   // This function turns off the headlights, if the joystick has been held down for two cycles of headlight #1's interval.
  345.   upDownValue = analogRead(joystick_upDown_axis);
  346.   // Below checks the timer to see if headllight 1 should be turned on.
  347.   if (upDownValue <= joystick_down_active_value) {
  348.     if (headlight_1_state == 1 || headlight_2_state == 1 ) { // Probably don't need to check #2 (#2 would not be on unless #1 was also) but anyway.
  349.       // NOTE: if you flip the joystick values, then you may need to flip the comparator signs above as well.
  350.       // This means the joystick is pushed left.
  351.       switch (headlights_off_trigger_count) {
  352.         case 0:
  353.           headlights_off_trigger_count = 1; // increment this trigger count to 1
  354.           break;
  355.         case 1:
  356.           // if the trigger count reaches 2, the left trigger count is reset to zero and headlight 1 is turned on here.
  357.           headlights_off_trigger_count = 0;
  358.           turn_off_headlight_1();
  359.           turn_off_headlight_2();
  360.           if (brake_light_mode == 1) {
  361.             // If the brake light is in low mode, turn it off here.
  362.             set_brake_light_off();
  363.           }
  364.           break;
  365.       }
  366.     }
  367.     if (print_joystick_upDown_messages == true) {
  368.       Serial.print("DOWN joystick detected: value = ");
  369.       Serial.println(upDownValue);
  370.     }
  371.   }
  372.  
  373. }
  374.  
  375.  
  376. void check_brake_input_value() {
  377.   // This function checks the brake input pin and turns the brake light to the [off] or [low] level as needed.
  378.   brake_control_current_time = millis();
  379.   if (brake_control_current_time > brake_control_begin_time) {
  380.     if (brake_control_current_time >= (brake_control_begin_time + brake_input_check_interval)) {
  381.       int buttonState = digitalRead(brake_trigger_pin);
  382.       if (buttonState == 1) {
  383.         if (brake_light_state == 0) {
  384.           brake_light_state = 1;
  385.           set_brake_light_high(); // Turn the brake light on high, any time the brake input pin is activated.
  386.           if (print_brake_input_messages == true) {
  387.             Serial.println("brake input = HIGH");
  388.           }
  389.         }
  390.       }
  391.       else { // If the brake input pin is low:
  392.         if (brake_light_state == 1) {
  393.           brake_light_state = 0;
  394.           if (headlight_1_state == 1 || headlight_2_state == 1) {
  395.             set_brake_light_low(); // If the headlights are on, turn the brake to 'low'.
  396.           }
  397.           else {
  398.             set_brake_light_off(); // If the headlights are off, turn the brake to 'off'.
  399.           }
  400.           if (print_brake_input_messages == true) {
  401.             Serial.println("brake input = LOW");
  402.           }
  403.         }
  404.       }
  405.       brake_control_begin_time = millis();
  406.     }
  407.   }
  408.   else {
  409.     brake_control_begin_time = millis();
  410.   }
  411. }
  412.  
  413.  
  414. void set_brake_light_off() {
  415.   // This turns the brake light pin off entirely.
  416.   if (print_brake_light_messages == true) {
  417.     Serial.println("set_brake_light_off() called");
  418.   }
  419.   analogWrite(brake_light_pin, 0);
  420. }
  421.  
  422.  
  423. void set_brake_light_low() {
  424.   // This turns the brake light pin to the 'low' setting (running light when the headlights are on).
  425.   if (print_brake_light_messages == true) {
  426.     Serial.println("set_brake_light_low() called");
  427.   }
  428.   analogWrite(brake_light_pin, brake_light_low_value);
  429. }
  430.  
  431.  
  432. void set_brake_light_high() {
  433.   // This turns the brake light pin on at the high setting.
  434.   if (print_brake_light_messages == true) {
  435.     Serial.println("set_brake_light_high() called");
  436.   }
  437.   analogWrite(brake_light_pin, brake_light_high_value);
  438. }
  439.  
  440.  
  441. void check_blinker_cancel_button_value() {
  442.   // This turns off the blinkers, if the cancel button has been held down for two interval cycles.
  443.   blinker_cancel_control_current_time = millis();
  444.   if (blinker_cancel_control_current_time > blinker_cancel_control_begin_time) {
  445.     if (blinker_cancel_control_current_time >= (blinker_cancel_control_begin_time + blinker_cancel_button_time_interval)) {
  446.       int buttonState = digitalRead(blinker_cancel_pin);
  447.       if (blinker_left_state == 1 || blinker_right_state == 1) {
  448.         if (print_blinker_cancel_button_messages == true) {
  449.           Serial.println("blinker cancel button press detected");
  450.         }
  451.         if (buttonState == 1) {
  452.           switch (blinkers_off_trigger_count) {
  453.             case 0:
  454.               blinkers_off_trigger_count = 1; // increment this trigger count to 1
  455.               break;
  456.             case 1:
  457.               // if the trigger count reaches 2, the trigger count is reset to zero and both blinkers can be turned off.
  458.               blinkers_off_trigger_count = 0;
  459.               stop_left_blinker();
  460.               stop_right_blinker();
  461.               if (print_blinker_cancel_button_messages == true) {
  462.                 Serial.println("blinkers turning off");
  463.               }
  464.               break;
  465.           }
  466.         }
  467.       }
  468.       blinker_cancel_control_begin_time = millis();
  469.     }
  470.   }
  471.   else {
  472.     blinker_cancel_control_begin_time = millis();
  473.   }
  474. }
  475.  
  476.  
  477. void start_left_blinker() {
  478.   // All that this function does is start the left blinker.
  479.   if (print_blinker_messages == true) {
  480.     Serial.println("start_left_blinker() called");
  481.   }
  482.   stop_right_blinker(); // Make sure the other blinker is turned off first.
  483.   blinker_left_state = 1;
  484.   blinker_left_LED_state = 1; // This should be zero anyway, but it can be set here to be certain.
  485.   digitalWrite(blinker_left_pin, blinker_left_LED_state);
  486.   blinker_interval_time = blinker_on_time;
  487.   blinker_blink_begin_time = millis();
  488. }
  489.  
  490.  
  491. void start_right_blinker() {
  492.   // All that this function does is start the right blinker.
  493.   if (print_blinker_messages == true) {
  494.     Serial.println("start_right_blinker() called");
  495.   }
  496.   stop_left_blinker(); // Make sure the other blinker is turned off first.
  497.   blinker_right_state = 1;
  498.   blinker_right_LED_state = 1; // This should be zero anyway, but it can be set here to be certain.
  499.   digitalWrite(blinker_right_pin, blinker_right_LED_state);
  500.   blinker_interval_time = blinker_on_time;
  501.   blinker_blink_begin_time = millis();
  502. }
  503.  
  504.  
  505. void stop_left_blinker() {
  506.   // All that this function does is shut off the left blinker.
  507.   if (print_blinker_messages == true) {
  508.     Serial.println("stop_left_blinker() called");
  509.   }
  510.   blinker_left_state = 0;
  511.   blinker_left_LED_state = 0;
  512.   change_left_blinker_pin();
  513. }
  514.  
  515.  
  516.  
  517. void stop_right_blinker() {
  518.   // All that this function does is shut off the right blinker.
  519.   if (print_blinker_messages == true) {
  520.     Serial.println("stop_right_blinker() called");
  521.   }
  522.   blinker_right_state = 0;
  523.   blinker_right_LED_state = 0;
  524.   change_right_blinker_pin();
  525. }
  526.  
  527.  
  528.  
  529. void check_blinker_state() {
  530.   // This function causes the blinker LEDs to switch on and off, if they are activated.
  531.  
  532.   // If the left blinker is {in use}, then this part switches the left blinker LED pin on and off on its own.
  533.   if (blinker_left_state == 1) {
  534.     blinker_blink_current_time = millis();
  535.     if (blinker_blink_current_time > blinker_blink_begin_time) {
  536.       if (blinker_blink_current_time >= (blinker_blink_begin_time + blinker_interval_time)) {
  537.         if (blinker_left_LED_state == 0) {
  538.           blinker_left_LED_state = 1;
  539.           blinker_interval_time = blinker_on_time;
  540.         }
  541.         else {
  542.           blinker_left_LED_state = 0;
  543.           blinker_interval_time = blinker_off_time;
  544.         }
  545.         change_left_blinker_pin();
  546.         blinker_blink_begin_time = millis();
  547.       }
  548.     }
  549.     else {
  550.       blinker_blink_begin_time = millis();
  551.     }
  552.   }
  553.  
  554.   // If the right blinker is {in use}, then this part switches the right blinker LED pin on and off on its own.
  555.   if (blinker_right_state == 1) {
  556.     blinker_blink_current_time = millis();
  557.     if (blinker_blink_current_time > blinker_blink_begin_time) {
  558.       if (blinker_blink_current_time >= (blinker_blink_begin_time + blinker_interval_time)) {
  559.         if (blinker_right_LED_state == 0) {
  560.           blinker_right_LED_state = 1;
  561.           blinker_interval_time = blinker_on_time;
  562.         }
  563.         else {
  564.           blinker_right_LED_state = 0;
  565.           blinker_interval_time = blinker_off_time;
  566.         }
  567.         change_right_blinker_pin();
  568.         blinker_blink_begin_time = millis();
  569.       }
  570.     }
  571.     else {
  572.       blinker_blink_begin_time = millis();
  573.     }
  574.   }
  575. }
  576.  
  577.  
  578.  
  579. void change_left_blinker_pin() {
  580.   // All that this function does is change the output pin value of the left blinker.
  581.   // This is a separate function so that a serial.print message can be attached to the pin change event.
  582.   if (print_blinker_messages == true) {
  583.     if (blinker_left_LED_state == 0) {
  584.       Serial.println("left blinker blinking off");
  585.     }
  586.     else {
  587.       Serial.println("left blinker blinking on");
  588.     }
  589.   }
  590.   digitalWrite(blinker_left_pin, blinker_left_LED_state);
  591. }
  592.  
  593.  
  594.  
  595. void change_right_blinker_pin() {
  596.   // All that this function does is change the output pin value of the right blinker.
  597.   // This is a separate function so that a serial.print message can be attached to the pin change event.
  598.   if (print_blinker_messages == true) {
  599.     if (blinker_right_LED_state == 0) {
  600.       Serial.println("right blinker blinking off");
  601.     }
  602.     else {
  603.       Serial.println("right blinker blinking on");
  604.     }
  605.   }
  606.   digitalWrite(blinker_right_pin, blinker_right_LED_state);
  607. }
Advertisement
Add Comment
Please, Sign In to add comment