Phoxtane

function 2

Mar 17th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. void blinkLED(int LEDpin, int blinkFlag){
  2.  
  3. /* takes the pin to 'blink' on, flag controls whether or not LED blinks (should be able to turn blink on/off with 1/0 respectively)
  4. */
  5.  
  6. static int blinkFlagValue = 0; // turns blinking on/off (1/0 respectively)
  7. const int blinkInterval = 1000; // time between switching LED output (ms)
  8. static int LEDState = LOW; // tracking if LED is on or off when function called
  9. static unsigned long previousMillis = 0; // contains value of currentValue from last time function was called
  10.  
  11.  
  12. unsigned long currentMillis = millis(); // get current millisecond count
  13.  
  14. Serial.println(currentMillis); // debug - show current value
  15. Serial.println(previousMillis); // debug - show past value
  16.  
  17. if((currentMillis - previousMillis >= blinkInterval) && blinkFlag == 1){ // compare current to previous and if longer than the specified interval, continue with function work
  18. previousMillis = currentMillis; // update past value for comparison next time function is called
  19. if(LEDState == LOW){ // check to see if LED is off
  20. LEDState = HIGH; // turn LED on (if LED is off)
  21. }
  22. else{
  23. LEDState = LOW; // turn LED off (if LED is on)
  24. }
  25.  
  26. digitalWrite(LEDpin, LEDState); // output to real hardware
  27. }
  28. Serial.println(LEDState); // debug - show current value of LEDState
  29. }
Advertisement
Add Comment
Please, Sign In to add comment