Facing problem in Arduino code.

UKHeliBob:
I thought that too, and it would make the code simpler, but looking closely I see

  else if (percent > 36 && percent <= 55)

{
   digitalWrite(led1, HIGH);
   digitalWrite(led2, LOW);
   digitalWrite(led3, LOW);
   delay(15000);
   digitalWrite(led1, LOW);
   digitalWrite(led2, HIGH);
   digitalWrite(led3, LOW);
   delay(15000);
   digitalWrite(led1, LOW);
   digitalWrite(led2, LOW);
   digitalWrite(led3, HIGH);
   delay(15000);
   digitalWrite(led2, LOW);
 }
 else if (percent > 56 && percent <= 85)
 {
   digitalWrite(led1, HIGH);
   digitalWrite(led2, LOW);
   digitalWrite(led3, LOW);
   delay(1000);
   digitalWrite(led1, LOW);
   digitalWrite(led2, HIGH);
   digitalWrite(led3, LOW);
   delay(1000);
   digitalWrite(led1, LOW);
   digitalWrite(led2, LOW);
   digitalWrite(led3, HIGH);
   delay(1000);
   digitalWrite(led2, LOW);
   digitalWrite(led3, LOW);
 }




The difference may, of course, be a mistake in the code

thank you for this..!

UKHeliBob:
Yes

thank you!

swami412:
thank you for this..!

So, was it a mistake and all of the patterns the same, just with different timing ?

swami412:
just need explanation for this instruction

while (!Serial && millis() < 5000) {}

On Arduino models with native USB (Leonardo, Micro, etc.) you are supposed to wait for "Serial" to be non-zero after calling Serial.begin(). If your Arduino is not connected to a USB host, "Serial" will remain zero. This line waits for up to 5 seconds for USB to connect and then goes on without it. On an Arduino UNO, Nano, Mega... the loop will end immediately since "Serial" is never zero.

johnwasser:
On Arduino models with native USB (Leonardo, Micro, etc.) you are supposed to wait for "Serial" to be non-zero after calling Serial.begin(). If your Arduino is not connected to a USB host, "Serial" will remain zero. This line waits for up to 5 seconds for USB to connect and then goes on without it. On an Arduino UNO, Nano, Mega... the loop will end immediately since "Serial" is never zero.

Thank you!
You've been very kind and alot helpful...

UKHeliBob:
So, was it a mistake and all of the patterns the same, just with different timing ?

Yess!
Thank you tho!

I wish that I had known that earlier because it makes the programming so much easier

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.