I am having issues with my code. It is a Binary clock which displays Minutes, Hrs and if it is AM or PM. My current issue is that when it starts all the green LEDs are meant to be out for the first minute but the first LED turns on and indicates that the first minute has already finished.
// pins 3 - 13 are the regular digital pwm pins.
int ledPinsMin[] = { 3, 4, 5, 6, 7, 8};
int ledPinsHr[] = { 9, 10, 11, 12,};
int ledPinsPM[] = {13};
// set Start time here
int countM = 0; // Minutes
int countH = 0; // Hours
int countP = 0; // Day time
byte countMin;
byte countHr;
byte countPM;
#define nBitsMin sizeof(ledPinsMin)/sizeof(ledPinsMin[0])
#define nBitsHr sizeof(ledPinsHr)/sizeof(ledPinsHr[0])
#define nBitsPM sizeof(ledPinsPM)/sizeof(ledPinsPM[0])
void setup(void)
{
int i;
for (i = 0; i < nBitsMin; i++); {
pinMode(ledPinsMin*, OUTPUT);*
- }*
- for (i = 0; i < nBitsHr; i++) {*
_ pinMode(ledPinsHr*, OUTPUT);_
_ }_
_ for (i = 0; i < nBitsPM; i++) {_
_ pinMode(ledPinsPM, OUTPUT);
}
}
void loop(void)
{
countM = (countM + 1);
if (countM > 59)
{
countM = 0;
countH = (countH + 1);
if (countH > 12)
{
countH = 0;
countP = (countP + 1);
if (countP > 11)
{
countP = 0;
countH = 0;
countM = 0;
}
}
}
dispBinaryMin(countM);
dispBinaryHr(countH);
dispBinaryPM(countP);
delay(60000); // Clock running speed.
}
void dispBinaryMin(byte nMin)
{
for (byte i = 0; i < nBitsMin; i++) {
digitalWrite(ledPinsMin, nMin & 1);
nMin /= 2;
}
}
void dispBinaryHr(byte nHr)
{
for (byte i = 0; i < nBitsHr; i++) {
digitalWrite(ledPinsHr, nHr & 1);
nHr /= 2;
}
}
void dispBinaryPM(byte nPM)
{
for (byte i = 0; i < nBitsPM; i++) {
digitalWrite(ledPinsPM, nPM & 1);
nPM /= 2;
}
}*_