Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int oldmillis, currentmillis, oldmillis2, currentmillis2, oldmillis3, currentmillis3, interval = 1000, interval2 = 2000, interval3 = 3000;
- bool time_past = LOW, pin = LOW, time_past2 = LOW, pin2 = LOW, time_past3 = LOW, pin3 = LOW;
- // use #define to save memory instead of variables (byte LED = 1) for pins that don't change anyway
- #define LED 1
- #define LED2 2
- #define LED3 3
- void setup() {
- Serial.begin(9600);
- pinMode(LED, OUTPUT);
- pinMode(LED2, OUTPUT);
- pinMode(LED3, OUTPUT);
- }
- void loop() {
- // This part is executed every 1 seconds
- // *********** BEGIN *******************
- if (time_past == LOW) // set oldmillis with the current value of millis () only if time_past is LOW
- {
- oldmillis = millis();
- time_past = HIGH;
- }
- currentmillis = millis(); // get current millis () and save it in the variable currentmillis
- if ((currentmillis - oldmillis) > interval) // only do the following if currrentmillis-oldmillis is greater than interval (1 second has passed)
- {
- time_past = LOW; //Set status for time_past to LOW so that it can be reset
- pin = !pin; // negate the value of pin, make LOW to HIGH, make High to LOW
- digitalWrite(LED, pin); //write the new value of pin to the digital output
- if (pin) Serial.println("LED 1= ON");
- if (!pin) Serial.println("LED 1= OFF");
- }
- // ************ END *******************
- // This part is executed every 2 seconds
- // *********** BEGIN *******************
- if (time_past2 == LOW) // set oldmillis with the current value of millis () only if time_past is LOW
- {
- oldmillis2 = millis();
- time_past2 = HIGH;
- }
- currentmillis2 = millis(); // get current millis () and save it in the variable currentmillis
- if ((currentmillis2 - oldmillis2) > interval2) // only do the following if currrentmillis-oldmillis is greater than interval2 (2 second has passed)
- {
- time_past2 = LOW; //Set status for time_past to LOW so that it can be reset
- pin2 = !pin2; // negate the value of pin, make LOW to HIGH, make High to LOW
- digitalWrite(LED2, pin2); //write the new value of pin to the digital output
- if (pin2) Serial.println("LED 2= ON");
- if (!pin2) Serial.println("LED 2= OFF");
- }
- // ************ END *******************
- // This part is executed every 3 seconds
- // *********** BEGIN *******************
- if (time_past3 == LOW) // set oldmillis with the current value of millis () only if time_past is LOW
- {
- oldmillis3 = millis();
- time_past3 = HIGH;
- }
- currentmillis3 = millis(); // get current millis () and save it in the variable currentmillis
- if ((currentmillis3 - oldmillis3) > interval3) // only do the following if currrentmillis-oldmillis is greater than interval3 (3 second has passed)
- {
- time_past3 = LOW; //Set status for time_past to LOW so that it can be reset
- pin3 = !pin3; // negate the value of pin, make LOW to HIGH, make High to LOW
- digitalWrite(LED3, pin3); //write the new value of pin to the digital output
- if (pin3) Serial.println("LED 3= ON");
- if (!pin3) Serial.println("LED 3= OFF");
- }
- // ************ END *******************
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement