Guest User

Untitled

a guest
Feb 24th, 2024
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. const int LED1 = 2, BPM1 = 40;
  2. const int LED2 = 3, BPM2 = 60;
  3. const int LED3 = 4, BPM3 = 90;
  4. const int LED4 = 5, BPM4 = 110;
  5. const int LED5 = 6, BPM5 = 130;
  6.  
  7. const int LEDduration = 50;
  8.  
  9. float delay1 = 60000 / BPM1;
  10. float delay2 = 60000 / BPM2;
  11. float delay3 = 60000 / BPM3;
  12. float delay4 = 60000 / BPM4;
  13. float delay5 = 60000 / BPM5;
  14.  
  15. class Blinking_LED
  16. {
  17. private:
  18. unsigned long previousMillis = 0;
  19. int isOn = 0;
  20.  
  21. public:
  22. void Blink(int ledPin, float delay, int duration)
  23. {
  24. // a function that can blink an LED independent from other functions
  25. // takes in LED pin number, delay between starts of blinks, duration of each blink
  26. unsigned long currentMillis = millis();
  27.  
  28. if (currentMillis - previousMillis >= delay && isOn == 0)
  29. {
  30. digitalWrite(ledPin, HIGH);
  31. previousMillis = currentMillis;
  32. isOn = 1;
  33. }
  34. else if (currentMillis - previousMillis >= duration && isOn == 1)
  35. {
  36. digitalWrite(ledPin, LOW);
  37. isOn = 0;
  38. }
  39. }
  40. };
  41.  
  42. Blinking_LED LED_obj1;
  43. Blinking_LED LED_obj2;
  44. Blinking_LED LED_obj3;
  45. Blinking_LED LED_obj4;
  46. Blinking_LED LED_obj5;
  47.  
  48. void setup()
  49. {
  50. // put your setup code here, to run once:
  51. pinMode(LED1, OUTPUT);
  52. pinMode(LED2, OUTPUT);
  53. pinMode(LED3, OUTPUT);
  54. pinMode(LED4, OUTPUT);
  55. pinMode(LED5, OUTPUT);
  56. }
  57.  
  58. void loop()
  59. {
  60. // put your main code here, to run repeatedly:
  61. LED_obj1.Blink(LED1, delay1, LEDduration);
  62. LED_obj2.Blink(LED2, delay2, LEDduration);
  63. LED_obj3.Blink(LED3, delay3, LEDduration);
  64. LED_obj4.Blink(LED4, delay4, LEDduration);
  65. LED_obj5.Blink(LED5, delay5, LEDduration);
  66. }
  67.  
Advertisement
Add Comment
Please, Sign In to add comment