Home > other >  Two traffic lights code, is correct, please give directions
Two traffic lights code, is correct, please give directions

Time:10-04

Novice small white, both spelled wrong, Daniel advice please

#include
Const int RED=2;
Const int YELLOW=3;
Const int GREEN=4;

Int s, rTime=20, gTime=15, yTime=3;
Int flagr=1, flagy=0, flagg=0;
Void setup () {
PinMode (RED, the OUTPUT);
PinMode (YELLOW, the OUTPUT);
PinMode (GREEN, the OUTPUT);
DigitalWrite (RED, LOW);
DigitalWrite (YELLOW, LOW);
DigitalWrite (GREEN, LOW);
MsTimer2: : set (1000, Tim);
MsTimer2: : start ();
Serial. The begin (9600);
S=rTime;

}
Void Tim ()
{
S -;
Serial. Println (s);
}
Void loop ()
{
If (s & gt;=0 & amp; & Flagr==1)
{
DigitalWrite (RED, HIGH);
}
The else
{
Flagr=0;
Flagg=1;
S=gTime;
DigitalWrite (RED, LOW);
}

If (s>=0 & amp; & Flagg==1)
{
DigitalWrite (GREEN, HIGH);
}
The else
{
Flagg=0;
Flagy=1;
S=yTime;
DigitalWrite (GREEN, LOW);
}

If (s & gt;=0 & amp; & Flagy==1)
{
DigitalWrite (YELLOW, HIGH);
}
The else
{
Flagy=0;
Flagr=1;
S=rTime;
DigitalWrite (YELLOW, LOW);
}

}

=====================================================================

#include
# define RED 2
# define YELLOW 3
# define GREEN 4
Int s, rTime=20, gTime=15, yTime=3;
Int flagr=1, flagy=0, flagg=0;
Void setup () {
PinMode (RED, the OUTPUT);
PinMode (YELLOW, the OUTPUT);
PinMode (GREEN, the OUTPUT);
DigitalWrite (RED, LOW);
DigitalWrite (YELLOW, LOW);
DigitalWrite (GREEN, LOW);
MsTimer2: : set (1000, Tim);
MsTimer2: : start ();
Serial. The begin (9600);
S=rTime;
}
Void Tim ()
{
S -;
Serial. Println (s);
}
Void loop ()
{
While (s> 0)
{
DigitalWrite (RED, HIGH);
}
Flagr=0;
Flagg=1;
DigitalWrite (RED, LOW);
S=gTime;

While (s> 0 & amp; & Flagg==1)
{
DigitalWrite (GREEN, HIGH);
}
Flagg=0;
Flagy=1;
DigitalWrite (GREEN, LOW);
S=yTime;

While (s> 0 & amp; & Flagy==1)
{
DigitalWrite (YELLOW, HIGH);
}
Flagy=0;
Flagr=1;
DigitalWrite (YELLOW, LOW);
S=rTime;

}

CodePudding user response:

The or on the print tone, plain to see
  • Related