sonyhome:
So people are sayingthat you don't really dim LEDs but turn them on rapdily then off, and the eye feels it is dimmer.
You could try to PWM your LEDs by using a simple C loop:
void dim(int on, const int pin) {
for (int i = 0; i < 1024; i++) {
if (i < on) {
digitalWrite(pin, HIGH);
} else {
digitalWrite(pin, LOW);
}
}
}
I call the same digitalWrite() routine in both cases every time to keep timings consistent.
passing 512 should make the LED 1/2 as bright...
sonyhome:
So people are sayingthat you don't really dim LEDs but turn them on rapdily then off, and the eye feels it is dimmer.
You could try to PWM your LEDs by using a simple C loop:
void dim(int on, const int pin) {
for (int i = 0; i < 1024; i++) {
if (i < on) {
digitalWrite(pin, HIGH);
} else {
digitalWrite(pin, LOW);
}
}
}
I call the same digitalWrite() routine in both cases every time to keep timings consistent.
passing 512 should make the LED 1/2 as bright...
Hi sonyhome, thanks for your reply. I tried to compile your code with mine.
is it something like this?
int SHCP_pin = 12;
int STCP_pin = 8;
int DS_pin = 11;
int on;
void setup()
{
pinMode(DS_pin, OUTPUT);
pinMode(STCP_pin, OUTPUT);
pinMode(SHCP_pin, OUTPUT);
writereg();
}
boolean registers[32];
void writereg()
{
digitalWrite (STCP_pin,LOW);
for (int i=31;i>=0;i--)
{
digitalWrite (SHCP_pin, LOW);
digitalWrite (DS_pin, registers[i]);
digitalWrite (SHCP_pin, HIGH);
}
digitalWrite (STCP_pin, HIGH);
}
void loop()
{
for (int i=0;i<32;i++)
{
registers[i]= HIGH;
delay (50);
writereg();
dim();
}
}
void dim() {
for (int i = 0; i < 1024; i++) {
if (i < on) {
digitalWrite(registers[i], HIGH);
} else {
digitalWrite(registers[i], LOW);
}
}
}
need help.