// Array of LED PINS. Makes it easy for our binary counter to decide which LEDS to blink.
//
int const PINS[] = {13, 12, 11, 10, 9};
int const PINS_SIZE = (sizeof(PINS)/sizeof(int));
int delayms = 0;
// the setup routine runs once when you press reset:
void setup() {
// initialize digital pins as outputs.
for(int led = 8; led < 14; led++){
pinMode(led, OUTPUT);
}
//Serial.begin(9600);
}
//Blinks LEDS in binary
void blink_binary_number(int number, boolean vol=HIGH){
for(int led = 0; led < PINS_SIZE; led++){
if (bitRead(number, led) == 1){
digitalWrite(PINS[led], vol); //Here we use our PINS array to decide which LED to blink. Since I wanted 13 to be bit 0, 12 bit 1, etc...
}
}
}
// the loop routine runs over and over again forever:
void loop() {
for(int x = 0; x < 32; x++){
delayms = analogRead(0) * 10;
if (x == 31){
analogWrite(8, 254);
}
blink_binary_number(x);
delay(delayms);
if (x == 31){
analogWrite(8, 0);
}
blink_binary_number(x, LOW);
delay(delayms);
}
}