Go Down

Topic: PROJECT 02 - SIMULTAN LOOPS (Read 1 time) previous topic - next topic

nico01gr

HELLO,
TRYING TO UNDERSTAND THE WORKING OF THIS PROJECT I HAVE ADDED (BESIDE THE 2 RED LEDS AND THE GREEN ONE) A YELLOW MORE. I WANTED TO MAKE IT BLINK WHILE THE SWITCH IS PRESSED IN A SEPARATE LOOP TO THE RED TWO. I HAVE PROBLEMS IN WRITING THE CODE FOR TWO OR MORE LOOPS WHICH ARE WORKING SEPARATLY.
LOOKING IN THE FORUM I FOUND A SOLUTION:
Quote
void setup()
{
    setupPart1();
    setupPart2();
    setupPart3();
}
void loop()
{
    loopPart1();
    loopPart2();
    loopPart3();
}


BUT I'M NOT YET SO FAR TO INCORPORATE MY CODE TO THE ABOVE.
WHAT I WANT IS THAT
THE YELLOW LED IS BLINKING EVERY 1/10 SEC WHILE THE TWO RED IN EVERY 2 SEC SEPARATLY.
HERE IS MY CODE WHICH DOES NOT GIVE THE RESULT I WANT.
Quote
int switchstate = 0;
void setup()
{
pinMode(2,INPUT);
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
pinMode(6,OUTPUT);
}
void loop()
{
  switchstate = digitalRead(2); // CHECKS THE VOLTAGE AT PIN 2
if (switchstate == LOW) //THE SWITCH IS NOT PRESSED, NO VOLTAGE AT PIN 2

   digitalWrite(6,LOW); //YELLOW LED IS OUT
}
else //THE SWITCH IS PRESSED,  VOLTAGE AT PIN 2
{
digitalWrite(6,HIGH); //YELLOW LED IS ON

delay(100); //WAIT 100/1000 OF A SECOND AND...

digitalWrite(6,LOW); //YELLOW LED IS OUT

delay(100); //WAIT 100/1000 OF A SECOND AND...
}
if (switchstate == LOW)  // THE SWITCH IS NOT PRESSED, NO VOLTAGE AT PIN 2

  digitalWrite(3,HIGH);  // GREEN LED IS ON
  digitalWrite(4,LOW);  // FIRST RED LED IS OUT
  digitalWrite(5,LOW);  // SECOND RED LED IS OUT
}
else
{
digitalWrite(3,LOW);  // GREEN LED IS OUT
  digitalWrite(4,HIGH);  // FIRST RED LED IS ON
  digitalWrite(5,LOW);  // SECOND RED LED IS OUT
 
delay(2000);  //WAIT 2 SECONDS AND...

digitalWrite(3,LOW);  // GREEN LED IS OUT
  digitalWrite(4,LOW);  // FIRST RED LED IS OUT
  digitalWrite(5,HIGH);  // SECOND RED LED IS ON

  delay(2000);  //WAIT 2 SECONDS AND...

}  // LOOP REPEATS


ANY HELP IS WELCOME!
THANK YOU
NICO

Go Up