58 lines
1.4 KiB
C++
58 lines
1.4 KiB
C++
int red = 5; //red led at pin
|
|
int green = 6; //green led at pin
|
|
int blue = 7; //blue led at pin
|
|
int redswitch = 8; //reading of switch at pin 8
|
|
int greenswitch = 9; //reading of switch at pin 9
|
|
int blueswitch = 10; //reading of switch at pin 10
|
|
int counter; //counts
|
|
int redtimer = 500; //length of red light's flashing
|
|
int greentimer = 700; //length of green light's flashing
|
|
int bluetimer = 900; //length of blue light's flashing
|
|
|
|
void setup() {
|
|
// put your setup code here, to run once:
|
|
pinMode(red,OUTPUT);
|
|
pinMode(green,OUTPUT);
|
|
pinMode(blue,OUTPUT);
|
|
pinMode(redswitch,INPUT);
|
|
pinMode(greenswitch,INPUT);
|
|
pinMode(blueswitch,INPUT);
|
|
counter = 0;
|
|
}
|
|
|
|
void loop() {
|
|
// put your main code here, to run repeatedly:
|
|
if (digitalRead(redswitch) == HIGH) {
|
|
if (((counter / redtimer) % 2) == 0) {
|
|
digitalWrite(red,HIGH);
|
|
} else {
|
|
digitalWrite(red,LOW);
|
|
}
|
|
} else {
|
|
digitalWrite(red,LOW);
|
|
}
|
|
|
|
if (digitalRead(greenswitch) == HIGH) {
|
|
if (((counter / greentimer) % 2) == 0) {
|
|
digitalWrite(green,HIGH);
|
|
} else {
|
|
digitalWrite(green,LOW);
|
|
}
|
|
} else {
|
|
digitalWrite(green,LOW);
|
|
}
|
|
|
|
if (digitalRead(blueswitch) == HIGH) {
|
|
if (((counter / bluetimer) % 2) == 0) {
|
|
digitalWrite(blue,HIGH);
|
|
} else {
|
|
digitalWrite(blue,LOW);
|
|
}
|
|
} else {
|
|
digitalWrite(blue,LOW);
|
|
}
|
|
|
|
counter = counter + 1;
|
|
delay(1);
|
|
}
|