Arduino


SUBMITTED BY: Guest

DATE: March 21, 2014, 9:10 a.m.

FORMAT: C++

SIZE: 1.1 kB

HITS: 3140

  1. // Constants, variables
  2. const int ledPin = 2; // the number of the LED pin
  3. long previousMillis = 0; // will store last time LED was updated
  4. long interval = 1000; // interval at which to blink (milliseconds)
  5. void setup() {
  6. // set the digital pin as output:
  7. pinMode(ledPin, OUTPUT);
  8. }
  9. void loop()
  10. {
  11. // check to see if it's time to blink the LED; that is, if the
  12. // difference between the current time and last time you blinked
  13. // the LED is bigger than the interval at which you want to
  14. // blink the LED.
  15. unsigned long currentMillis = millis();
  16. if(currentMillis - previousMillis > interval) {
  17. // save the last time you blinked the LED
  18. previousMillis = currentMillis;
  19. // set the LED with the ledState of the variable:
  20. digitalWrite(ledPin, HIGH);
  21. delay(100);
  22. digitalWrite(ledPin, LOW);
  23. }
  24. }

comments powered by Disqus