# PWM in smaller increments to dimm ledstrip

@Dlloyd, Thx, missed your post. Will try it out but don't understand how using analogwrite can accept a smaller value than 1 and thus dimming less than 1 by playing with the dutycycle. (Probably out of my league :)

By playing with the duty cycle (creating a 1 count jitter that follows 8 different patterns) we get 8 more steps of brightness for each original step in duty cycle, so we end up with 11-bit control range.

I thought I'd give it a try ... just connect a super-bright LED to pin 13 (I used red with 1K resistor). I created test code that increases the brightness from 0 - 24 in one second intervals, then repeats. The actual duty cycle value the PWM will see is 0 - 3 with +1 jitter pattern.

I could see 24 distinct and steady changes in brightness, whereas originally there would only be 3.

Give it a try:

``````unsigned short val = 0; // 0-2047 (brightness range)
const long interval = 1000;
unsigned long previousMillis = 0;

void setup() {
pinMode(13, OUTPUT);
}

void loop() {
unsigned long currentMillis = millis();
analogWrite(13, duty());

if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
val += 1;
(val > 24) ? val = 0 : val;
}
}

unsigned short duty () {
byte fine[] = {B0, B1, B00010001, B01001010, B01010110, B01101011, B01110111, B11111111};
unsigned short dty;
byte mx = millis() % 8;
(val > 2047) ? val = 2047 : val;
dty = val >> 3;
dty += (fine[val & 7] >> mx) & 1;
(dty > 255) ? dty = 255 : dty;
return dty;
}
``````