tinkerspy / Automaton

Reactive State Machine Framework for Arduino
https://github.com/tinkerspy/Automaton/wiki
MIT License
374 stars 63 forks source link

Gamma correction for LED fading #65

Open Bomaker opened 5 years ago

Bomaker commented 5 years ago

Hi, Could you add a gamma correction for LED brightness? It can be learned from "LED.cpp - Library for LEDs. Created by Benjamin Wüst" which I cannot find anymore on github (have a local copy though).

int LED::calculate_linear_fade_position_to_exponential(int position, double pwm_max_steps, double gamma_correction)
{
 // This function needs scientific backup!
 // http://www.wolframalpha.com/input/?i=plot+y%3Dround%28255*%28x%2F255%29^%282.2%29%29+from+x%3D0+to+255
 int out = round(pwm_max_steps * ( pow( (position/ 255.0) , gamma_correction) ));
 return out;
} 

Gamma of 2.2 seems to be good. BTW, why isn't the bool activeLow = false not working with fade? Cool library nevertheless! Thanks!