blinking_2_instances.pde 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // This code will blink output 13 every 250 ms
  2. // abd will blink output 9 every 125 ms
  3. #include <Metro.h> // Include Metro library
  4. #define LED0 13 // Define a LED pin
  5. #define LED1 9 // Define another LED pin
  6. // Create variables to hold the LED states
  7. int state0 = HIGH;
  8. int state1 = HIGH;
  9. // Instantiate a metro object and set the interval to 250 milliseconds (0.25 seconds).
  10. Metro metro0 = Metro(500);
  11. // Instantiate another metro object and set the interval to 125 milliseconds (0.125 seconds).
  12. Metro metro1 = Metro(125);
  13. void setup()
  14. {
  15. pinMode(LED0,OUTPUT);
  16. digitalWrite(LED0,state0);
  17. pinMode(LED1,OUTPUT);
  18. digitalWrite(LED1,state1);
  19. }
  20. void loop()
  21. {
  22. if (metro0.check() == 1) { // check if the metro has passed its interval .
  23. if (state0==HIGH) {
  24. state0=LOW;
  25. } else {
  26. state0=HIGH;
  27. }
  28. digitalWrite(LED0,state0);
  29. }
  30. if (metro1.check() == 1) { // check if the metro has passed its interval .
  31. if (state1==HIGH) {
  32. state1=LOW;
  33. } else {
  34. state1=HIGH;
  35. }
  36. digitalWrite(LED1,state1);
  37. }
  38. }