Skip to content

Instantly share code, notes, and snippets.

@matthewhughes
Created July 30, 2015 14:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matthewhughes/2b6695009d828f344b99 to your computer and use it in GitHub Desktop.
Save matthewhughes/2b6695009d828f344b99 to your computer and use it in GitHub Desktop.
Millis Delay Example
const int ledPin = 13;
int ledState = LOW;
long previousTime = 0;
long interval = 1000;
void setup() {
pinMode(ledPin, OUTPUT);
}
void loop()
{
unsigned long currentTime = millis();
if(currentTime - previousTime > interval) {
previousTime = currentTime;
if (ledState == LOW)
ledState = HIGH;
else
ledState = LOW;
digitalWrite(ledPin, ledState);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment