I'm trying to set a condition to every subroutine. And to run only the subroutine whereof the condition is true.
Now is running all of the subroutines constantly.
How do i need to set the conditions? or how can i let run that one specific subroutine and skip the others?
Who can help me?
int sensePin =A0;
int sensorValue = 0;
int Button1 = 13;
int Button2 = 12;
int Button3 = 11;
int Buttonstate1 = 0;
int Buttonstate2 = 0;
int Buttonstate3 = 0;
void setup() {
Serial.begin(9600);
pinMode(13,INPUT);
pinMode(12,INPUT);
pinMode(11,INPUT);
// initialize digital pin LED_BUILTIN as an output.
pinMode(2, OUTPUT);
Serial.begin(9600);
// initialize digital pin LED_BUILTIN as an output.
pinMode(3, OUTPUT);
Serial.begin(9600);
// initialize digital pin LED_BUILTIN as an output.
pinMode(4, OUTPUT);
Serial.begin(9600);
// initialize digital pin LED_BUILTIN as an output.
pinMode(5, OUTPUT);
Serial.begin(9600);
// initialize digital pin LED_BUILTIN as an output.
pinMode(6, OUTPUT);
Serial.begin(9600);
// initialize digital pin LED_BUILTIN as an output.
pinMode(7, OUTPUT);
Serial.begin(9600);
// initialize digital pin LED_BUILTIN as an output.
pinMode(8, OUTPUT);
Serial.begin(9600);
// initialize digital pin LED_BUILTIN as an output.
pinMode(9, OUTPUT);
Serial.begin(9600);
// initialize digital pin LED_BUILTIN as an output.
pinMode(10, OUTPUT);
Serial.begin(9600);
}
// the loop function runs over and over again forever
void loop() {
Buttonstate1 = digitalRead(Button1);
Buttonstate2 = digitalRead(Button2);
Buttonstate3 = digitalRead(Button3);
if (Buttonstate1 == HIGH)
{
LooplichtL(); // action A
Serial.println("LooplichtL ON");
}
if (digitalRead (Button2) == HIGH)
{
LooplichtR(); // action B
Serial.println("LooplichtR ON");
}
sensorValue = analogRead (A0);
}
void LooplichtL ()
{
digitalWrite(10, HIGH); // turn the LED on (HIGH is the voltage level)
delay(sensorValue); // wait for a second
digitalWrite(10, LOW); // turn the LED off by making the voltage LOW
digitalWrite(9, HIGH); // turn the LED on (HIGH is the voltage level)
delay(sensorValue); // wait for a second
digitalWrite(9, LOW); // turn the LED off by making the voltage LOW
digitalWrite(8, HIGH); // turn the LED on (HIGH is the voltage level)
delay(sensorValue); // wait for a second
digitalWrite(8, LOW); // turn the LED off by making the voltage LOW
digitalWrite(7, HIGH); // turn the LED on (HIGH is the voltage level)
delay(sensorValue); // wait for a second
digitalWrite(7, LOW); // turn the LED off by making the voltage LOW
digitalWrite(6, HIGH); // turn the LED on (HIGH is the voltage level)
delay(sensorValue); // wait for a second
digitalWrite(6, LOW); // turn the LED off by making the voltage LOW
digitalWrite(5, HIGH); // turn the LED on (HIGH is the voltage level)
delay(sensorValue); // wait for a second
digitalWrite(5, LOW); // turn the LED off by making the voltage LOW
digitalWrite(4, HIGH); // turn the LED on (HIGH is the voltage level)
delay(sensorValue); // wait for a second
digitalWrite(4, LOW); // turn the LED off by making the voltage LOW
digitalWrite(3, HIGH); // turn the LED on (HIGH is the voltage level)
delay(sensorValue); // wait for a second
digitalWrite(3, LOW); // turn the LED off by making the voltage LOW
digitalWrite(2, HIGH); // turn the LED on (HIGH is the voltage level)
delay(sensorValue); // wait for a second
digitalWrite(2, LOW); // turn the LED off by making the voltage LOW
digitalWrite(1, HIGH); // turn the LED on (HIGH is the voltage level)
delay(sensorValue); // wait for a second
digitalWrite(1, LOW); // turn the LED off by making the voltage LOW
}
void LooplichtR ()
{
digitalWrite(1, HIGH); // turn the LED on (HIGH is the voltage level)
delay(sensorValue); // wait for a second
digitalWrite(1, LOW); // turn the LED off by making the voltage LOW
digitalWrite(2, HIGH); // turn the LED on (HIGH is the voltage level)
delay(sensorValue); // wait for a second
digitalWrite(2, LOW); // turn the LED off by making the voltage LOW
digitalWrite(3, HIGH); // turn the LED on (HIGH is the voltage level)
delay(sensorValue); // wait for a second
digitalWrite(3, LOW); // turn the LED off by making the voltage LOW
digitalWrite(4, HIGH); // turn the LED on (HIGH is the voltage level)
delay(sensorValue); // wait for a second
digitalWrite(4, LOW); // turn the LED off by making the voltage LOW
digitalWrite(5, HIGH); // turn the LED on (HIGH is the voltage level)
delay(sensorValue); // wait for a second
digitalWrite(5, LOW); // turn the LED off by making the voltage LOW
digitalWrite(6, HIGH); // turn the LED on (HIGH is the voltage level)
delay(sensorValue); // wait for a second
digitalWrite(6, LOW); // turn the LED off by making the voltage LOW
digitalWrite(7, HIGH); // turn the LED on (HIGH is the voltage level)
delay(sensorValue); // wait for a second
digitalWrite(7, LOW); // turn the LED off by making the voltage LOW
digitalWrite(8, HIGH); // turn the LED on (HIGH is the voltage level)
delay(sensorValue); // wait for a second
digitalWrite(8, LOW); // turn the LED off by making the voltage LOW
digitalWrite(9, HIGH); // turn the LED on (HIGH is the voltage level)
delay(sensorValue); // wait for a second
digitalWrite(9, LOW); // turn the LED off by making the voltage LOW
digitalWrite(10, HIGH); // turn the LED on (HIGH is the voltage level)
delay(sensorValue); // wait for a second
digitalWrite(10, LOW); // turn the LED off by making the voltage LOW
}