Blinking 1 LED with respect the value of the binary number?

Hello,

I'm working on a project where I have one LED and in every 30 seconds I'm looking for an event and I increase the counter if the conditions are satisfied. Now, I'm trying to blink the LED according to the number of the counter. For example, lets say the count is 5, so in 8 bit binary system it is 00000101. I want to keep the LED on or or for one second for every bit from MSB to LSB. How can this be done? I've written the code below but couldn't solve the problem above. Thanks in advance.

``````void loop() {

unsigned long time = millis();
const unsigned long halfMinutes = 0.1 * 60 * 1000;
static unsigned long lastSampleTime = 0 - halfMinutes;

if (time - lastSampleTime >= halfMinutes){              //If Half minute is passed, do the desired operations
lastSampleTime = lastSampleTime + halfMinutes;        //Set the time of sample
if(conditions){
count = count + 1;                                  //Increase the counter
Serial.print("Count is: ");                         //Print as 8 bit binary
printBits(count);
Serial.println("\n");
}
}
}

void printBits(byte myByte){
Serial.print('1');
else
Serial.print('0');
}
}
``````

Got the solution now, sorry for the bad question…

solijoli: I want to keep the LED on or or for one second for every bit from MSB to LSB. How can this be done?

This is one of those "one minute wonder" ideas.

Which is to say, a nice exercise in programming, but so boring as to be useless after a minute or so! :roll_eyes:

Well, five minutes if you are the one writing the code. :grinning: