I was just playing around trying to get different LEDs to flash at different rates, so I created this. I realized that if I set the delay to 1000 milliseconds, I could use it as a clock of sorts.
/*
binary countdowntime
Kenneth Thomas January 5, 2016
Open source..
*/
int greenLED = 13;
int redLED = 12;
int blueLED = 11;
int whiteLED = 10;
int flash = 1000;
void setup() {
// initialize digital pin 13 as an output.
pinMode(13, OUTPUT); //green
pinMode(12, OUTPUT); //red
pinMode(11, OUTPUT); //blue
pinMode(10, OUTPUT); //white
}
void loop() {
for(int x = 0; x < 8; x++){
if(x==0){
digitalWrite(10, HIGH);
digitalWrite(13,HIGH);
digitalWrite(12,HIGH);
digitalWrite(11,HIGH);
delay(flash);
digitalWrite(11,LOW);
delay(flash);
} else if(x==1){
digitalWrite(12,LOW);
digitalWrite(11,HIGH);
delay(flash);
digitalWrite(11,LOW);
delay(flash);
} else if(x==2){
digitalWrite(13, LOW);
digitalWrite(12, HIGH);
digitalWrite(11, HIGH);
delay(flash);
digitalWrite(11, LOW);
delay(flash);
} else if(x==3){
digitalWrite(12, LOW);
digitalWrite(11, HIGH);
delay(flash);
digitalWrite(11, LOW);
delay(flash);
} else if(x==4){
digitalWrite(10, LOW);
digitalWrite(13,HIGH);
digitalWrite(12,HIGH);
digitalWrite(11,HIGH);
delay(flash);
digitalWrite(11,LOW);
delay(flash);
} else if(x==5){
digitalWrite(12,LOW);
digitalWrite(11,HIGH);
delay(flash);
digitalWrite(11,LOW);
delay(flash);
} else if(x==6){
digitalWrite(13, LOW);
digitalWrite(12, HIGH);
digitalWrite(11, HIGH);
delay(flash);
digitalWrite(11, LOW);
delay(flash);
} else if(x==7){
digitalWrite(12, LOW);
digitalWrite(11, HIGH);
delay(flash);
digitalWrite(11, LOW);
delay(flash);
}
}
}
Top Comments