Thank you very much PaulRB for you valuable responses...
I changed the below code to 1/4 duty cycle as you said...now brightness is perfect...but the code has some problem when i turn off an led, it is not turning off, form loop section. when i turn off timer then it turns off. i don't know why?
#include <TimerOne.h>
//pin connections- the #define tag will replace all instances of "latchPin" in your code with A1 (and so on)
#define latchPin 4
#define clockPin 5
#define dataPin 7
byte ledData[] = {0, 0, 0, 0};
void setLED(int r, int c, bool flag){
bitWrite(ledData[r], c, flag);
}
void setup() {
//set pins as output
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
setLED(0,0,true);
setLED(0,1,true);
setLED(0,2,true);
setLED(0,3,true);
setLED(1,0,true);
setLED(1,1,true);
setLED(1,2,true);
setLED(1,3,true);
setLED(2,0,true);
setLED(2,1,true);
setLED(2,2,true);
setLED(2,3,true);
Timer1.initialize(500); // set a timer of length 100000 microseconds (or 0.1 sec - or 10Hz => the led will blink 5 times, 5 cycles of on-and-off, per second)
Timer1.attachInterrupt( timerIsr );
}
void turnOnLED() {
int i;
for (i=0;i<4;i++){
digitalWrite(latchPin, LOW);
byte dataToSend = (1 << (i+4)) | (15 & ~ledData[i]);
shiftOut(dataPin, clockPin, LSBFIRST, dataToSend);
digitalWrite(latchPin, HIGH);
}
}
void loop() {
setLED(2,3,false);
}
void timerIsr()
{
turnOnLED();
TCNT0=0xCC;
}