Hello, I would like to have two "void loop()"-functions that would run independantly but simultaneously.
Like that in one loop the could would read a buttons state every twenty milliseconds. then on the second loop it would control ports 2-5 like this:
void loop1(){
button = digitalRead(9); //read push-button
if (buttonmode == HIGH && beforebutton == LOW) {
mode++;
if (mode > 2) {
mode = 1;
}
}
beforebutton = buttonmode;
delay(20);
}
void loop2() {
//----potentiometers 1 and two----
int pot1 = analogRead(A0);
int pot2 = analogRead(A1);
//----potentiometers 1 and two----
if (mode==1) {
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
delay(pot1);
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
delay(pot2);
}
else if (mode==2){
digitalWrite(2,HIGH);
delay(pot1+pot2);
digitalWrite(2,LOW);
digitalWrite(3,HIGH);
delay(pot1+pot2);
digitalWrite(3,LOW);
digitalWrite(4,HIGH);
delay(pot1+pot2);
digitalWrite(4,LOW);
digitalWrite(5,HIGH);
delay(pot1+pot2);
digitalWrite(5,LOW);
}
}
So at the start mode 1 starts running and it puts ports 2-5 on HIGH, waits for potentiometer one ms (0-1023ms), puts ports 2-5 on LOW and waits for potentiometer two (0-1023)
when you press the button it would then switch onto mode 2 what firsts but pin 2 on HIGH, waits for potentiometer one+two ms (0-20246ms), puts pin two on LOW, waits for 0-2s, puts pin 3 on HIGH, waits for two seconds, puts pin 3 on LOW etc.
and it would be nice that the code reads on what state the button is at pretty fast rate like 20ms. but if you let it run simultaneously pot1 and pot2 could extend it to like 4 second or so
Is there any easy way to do it?
