Portfolio. BHSAD Arduino Prototyping | L4, Harduino: Drawing light | страница 7
int pinleds[6]={13,11,10,6,5,3};
int leds[]={LOW, LOW, LOW,
LOW, LOW, LOW,};
#define TIME_GREEN 5000
#define TIME_RED 5000
#define TIME_YELLOW 3000
#define TIME_BLINK 300
boolean blinkyellow=true;
void setup() {
for(int i=0;i<6;i++) {
pinMode(pinleds[i], OUTPUT);
digitalWrite(pinleds[i],leds[i]); }
}
blinkyellow, HIGH, HIGH, (int)
blinkyellow, LOW};
trafficlight(leds4);
delay(TIME_BLINK);
blinkyellow=!blinkyellow; }
}
Traffic light. Part 2
void trafficlight(int statled[5]) {
for(int i=0;i<6;i++) {
digitalWrite(pinleds[i],statled[i]);
}
}
void loop() {
int leds1[]={HIGH, LOW, LOW,
LOW, LOW, HIGH};
trafficlight(leds1);
delay(TIME_GREEN);
blinkyellow=true;
for(int i=0;i<(TIME_YELLOW/
TIME_BLINK); i++) {
int leds2[]={HIGH, (int)
blinkyellow, LOW, LOW, (int)
blinkyellow, HIGH};
trafficlight (leds2);
delay(TIME_BLINK);
blinkyellow=!blinkyellow;
}
for(int i=0;i