Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void blinkLED(int LEDpin, int blinkFlag){
- /* 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)
- */
- static int blinkFlagValue = 0; // turns blinking on/off (1/0 respectively)
- const int blinkInterval = 1000; // time between switching LED output (ms)
- static int LEDState = LOW; // tracking if LED is on or off when function called
- static unsigned long previousMillis = 0; // contains value of currentValue from last time function was called
- unsigned long currentMillis = millis(); // get current millisecond count
- Serial.println(currentMillis); // debug - show current value
- Serial.println(previousMillis); // debug - show past value
- if((currentMillis - previousMillis >= blinkInterval) && blinkFlag == 1){ // compare current to previous and if longer than the specified interval, continue with function work
- previousMillis = currentMillis; // update past value for comparison next time function is called
- if(LEDState == LOW){ // check to see if LED is off
- LEDState = HIGH; // turn LED on (if LED is off)
- }
- else{
- LEDState = LOW; // turn LED off (if LED is on)
- }
- digitalWrite(LEDpin, LEDState); // output to real hardware
- }
- Serial.println(LEDState); // debug - show current value of LEDState
- }
Advertisement
Add Comment
Please, Sign In to add comment