Advertisement
Guest User

Untitled

a guest
Apr 25th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. const int ledPin = 0;// the number of the LED pin
  2.  
  3. // Variables will change :
  4. int ledState = LOW; // ledState used to set the LED
  5.  
  6. // Generally, you should use "unsigned long" for variables that hold time
  7. // The value will quickly become too large for an int to store
  8. unsigned long previousMillis = 0; // will store last time LED was updated
  9.  
  10. // constants won't change :
  11. const long led_interval = 250; // interval at which to blink (milliseconds)
  12. const long lcd_interval = 1000;
  13.  
  14. void setup() {
  15. // set the digital pin as output:
  16. pinMode(ledPin, OUTPUT);
  17. }
  18.  
  19. void loop() {
  20. // here is where you'd put code that needs to be running all the time.
  21.  
  22. // check to see if it's time to blink the LED; that is, if the
  23. // difference between the current time and last time you blinked
  24. // the LED is bigger than the interval at which you want to
  25. // blink the LED.
  26. unsigned long currentMillis = millis();
  27.  
  28. if (currentMillis - previousMillis >= led_interval) {
  29. // save the last time you blinked the LED
  30. previousMillis = currentMillis;
  31.  
  32. // if the LED is off turn it on and vice-versa:
  33. if (ledState == LOW) {
  34. ledState = HIGH;
  35. led_interval = 500;
  36. } else {
  37. ledState = LOW;
  38. led_interval = 250;
  39. }
  40.  
  41. // set the LED with the ledState of the variable:
  42. digitalWrite(ledPin, ledState);
  43. }
  44.  
  45. if (currentMillis - previousMillis >= lcd_interval) {
  46. // save the last time you blinked the LED
  47. previousMillis = currentMillis;
  48.  
  49. // do the LCD shit here
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement