unsigned long pre1 = 0;
unsigned long pre2 = 0;
unsigned long pre3 = 0;
unsigned long pre4 = 0;
unsigned long timer1 = 500;
unsigned long timer2 = 1000;
unsigned long timer3 = 2000;
unsigned long timer4 = 3000;
unsigned long current1 = 0;
unsigned long current2 = 0;
unsigned long current3 = 0;
unsigned long current4 = 0;
int led1 = 1;
int led2 = 1;
int led3 = 1;
int led4 = 1;
int state = 0;
void setup() {
//Serial.begin(115200);
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
pinMode(11, OUTPUT);
pinMode(10, OUTPUT);
pinMode(8, OUTPUT);
pinMode(2, INPUT_PULLUP);
//attachInterrupt(0, blink, CHANGE);
attachInterrupt(digitalPinToInterrupt(2), blink, CHANGE);
}
void loop() {
current1 = millis();
if (current1 - pre1 >= timer1) {
//Serial.println(pre1);
pre1 = current1;
if (led1 == LOW) {
led1 = HIGH;
} else {
led1 = LOW;
}
digitalWrite(13, led1);
}
current2 = millis();
if (current2 - pre2 >= timer2) {
//Serial.println(pre2);
pre2 = current2;
if (led2 == LOW) {
led2 = HIGH;
} else {
led2 = LOW;
}
digitalWrite(12, led2);
}
current3 = millis();
if (current3 - pre3 >= timer3) {
// Serial.println(pre1);
pre3 = current3;
if (led3 == LOW) {
led3 = HIGH;
} else {
led3 = LOW;
}
digitalWrite(11, led3);
}
current4 = millis();
if (current4 - pre4 >= timer4) {
// Serial.println(pre4);
pre4 = current4;
if (led4 == LOW) {
led4 = HIGH;
} else {
led4 = LOW;
}
digitalWrite(10, led4);
}
digitalWrite(8, state);
}
void blink () {
/*if (state == 0){
state = 1;
}else {
state = 0;*/
state = !state;
}