Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const int LED1 = 2, BPM1 = 40;
- const int LED2 = 3, BPM2 = 60;
- const int LED3 = 4, BPM3 = 90;
- const int LED4 = 5, BPM4 = 110;
- const int LED5 = 6, BPM5 = 130;
- const int LEDduration = 50;
- float delay1 = 60000 / BPM1;
- float delay2 = 60000 / BPM2;
- float delay3 = 60000 / BPM3;
- float delay4 = 60000 / BPM4;
- float delay5 = 60000 / BPM5;
- class Blinking_LED
- {
- private:
- unsigned long previousMillis = 0;
- int isOn = 0;
- public:
- void Blink(int ledPin, float delay, int duration)
- {
- // a function that can blink an LED independent from other functions
- // takes in LED pin number, delay between starts of blinks, duration of each blink
- unsigned long currentMillis = millis();
- if (currentMillis - previousMillis >= delay && isOn == 0)
- {
- digitalWrite(ledPin, HIGH);
- previousMillis = currentMillis;
- isOn = 1;
- }
- else if (currentMillis - previousMillis >= duration && isOn == 1)
- {
- digitalWrite(ledPin, LOW);
- isOn = 0;
- }
- }
- };
- Blinking_LED LED_obj1;
- Blinking_LED LED_obj2;
- Blinking_LED LED_obj3;
- Blinking_LED LED_obj4;
- Blinking_LED LED_obj5;
- void setup()
- {
- // put your setup code here, to run once:
- pinMode(LED1, OUTPUT);
- pinMode(LED2, OUTPUT);
- pinMode(LED3, OUTPUT);
- pinMode(LED4, OUTPUT);
- pinMode(LED5, OUTPUT);
- }
- void loop()
- {
- // put your main code here, to run repeatedly:
- LED_obj1.Blink(LED1, delay1, LEDduration);
- LED_obj2.Blink(LED2, delay2, LEDduration);
- LED_obj3.Blink(LED3, delay3, LEDduration);
- LED_obj4.Blink(LED4, delay4, LEDduration);
- LED_obj5.Blink(LED5, delay5, LEDduration);
- }
Advertisement
Add Comment
Please, Sign In to add comment