int Led1 = 2;
int Led2 = 3;
int Led3 = 4;
int Led4 = 5;
int Led5 = 6;
int Led6 = 7;
int Led7 = 8;
int Led8 = 9;
int decVal = 0;
int Leds[8] = {Led1, Led2, Led3, Led4, Led5, Led6, Led7, Led8};
void LedDis(int status, int ledNum) {
if (status == 1) {
digitalWrite(Leds[ledNum], HIGH);
} else if (status == 0) {
digitalWrite(Leds[ledNum], LOW);
}
}
void decToBinary(int n) {
int binaryNum[8] = {};
int i = 0;
while (n > 0) {
binaryNum[i] = n % 2;
n = n / 2;
i++;
}
int bits = 8;
if ( i > 8 ) {
bits = 8*((i + 7)/8);
}
for (int j = bits-1; j >= 0; j--) {
LedDis(binaryNum[j], j);
Serial.print(binaryNum[j]);
}
Serial.println();
}
void setup() {
pinMode(Led1, OUTPUT);
pinMode(Led2, OUTPUT);
pinMode(Led3, OUTPUT);
pinMode(Led4, OUTPUT);
pinMode(Led5, OUTPUT);
pinMode(Led6, OUTPUT);
pinMode(Led7, OUTPUT);
pinMode(Led8, OUTPUT);
Serial.begin(9600);
}
void loop() {
decVal = 15;
decToBinary(decVal);
delay(500);
decVal = 35;
decToBinary(decVal);
delay(500);
decVal = 63;
decToBinary(decVal);
delay(500);
for (int x = 0; x < 20; x++) {
decVal += 1;
decToBinary(decVal);
delay(500);
}
}