# My 3 Leds clock needs help

need help and guide to program my 3 leds clock.
My idea about this 3 leds clock is that every 3 leds flashes in 3 different interval of 300, 500 and 1000 to represent 9 number, and when they all flash at 100 mills-second time interval, it means 0.
Below is the code I have written so far, I want to push a number to add 1 to number and have the leds flash the equivalent number.
Any help will be appreciated.

``````int rLed[]={1,2,3};
int gLed=4;
int bt=5;
int ledstate[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
unsigned long pstimer[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int number=-1;

void setup(){
pinMode(1, OUTPUT);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, INPUT_PULLUP);
}

void loop(){

number++;
}}

if(number==0) {

}

int ledblink(int sec, int pin,int x){
unsigned long timer[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
timer[x]=millis();
if(timer[x] - pstimer[x] > sec){
pstimer[x]=timer[x];
if (ledstate[x]==0)ledstate[x]=1;
else ledstate[x]=0;
digitalWrite(pin, ledstate[x]);
}

}
``````

I think you mean that you have three outputs, and you want each output to blink at one of four distinct frequencies.

In that case I'd use the code in 'blink without delay' but use an array to hold the pin numbers, blink intervals and blink times for each output. Then just process all the outputs in a FOR loop testing whether it is time for any of them to change output state.

It would need some simple code to convert your nine possible output states to the corresponding set of output blink intervals.

As a subtlety, when switching to 'zero' you would probably want to reset all the blink times so all the outputs are in phase with each other.

thanks for the help

PeterH:
I think you mean that you have three outputs, and you want each output to blink at one of four distinct frequencies.

In that case I'd use the code in 'blink without delay' but use an array to hold the pin numbers, blink intervals and blink times for each output. Then just process all the outputs in a FOR loop testing whether it is time for any of them to change output state.

It would need some simple code to convert your nine possible output states to the corresponding set of output blink intervals.

As a subtlety, when switching to 'zero' you would probably want to reset all the blink times so all the outputs are in phase with each other.