Comments (3)
Tried a non-async 20ms step (1.5s 0-100%) fade and it's very smooth:
from machine import Pin, PWM
from time import sleep_ms
def fadein():
led=PWM(Pin(12))
for i in range(0, 1024, 13): # 13 = 1024/(1500ms/20ms)
led.duty(i)
sleep_ms(20)
from led_strip.
On the point:
Brightness appear to be non-linear
I found that using an exponential function gave a better-looking response - in my case in the WiLED project I had a notion of "brightness steps", i.e. the dimmer would change between say five distinct levels only, rather than the full range PWM values. Then I have a mapping between those brightness levels and an actual PWM value. I suppose if you wanted to do 100 "brightness steps" then those would effectively be a percentage to PWM mapping.
The C++ code I have for it is:
float max_log10 = log10(led->getMaxPWM());
float steps_log10 = log10(NUM_DIM_STEPS-1);
float exponent = max_log10/steps_log10;
float result;
pwm_dim_levels[0] = 0;
for(int idx=1; idx<NUM_DIM_STEPS; idx++){
result = pow(idx,exponent);
pwm_dim_levels[idx] = int(result);
}
pwm_dim_levels[NUM_DIM_STEPS-1] = led->getMaxPWM();
The gist of it is though, suppose you want 8-bit values and 6 steps, you find the exponent with exponent = log10(255)/log10(6) = 3.092638069
and then the actual value with pwm = step ^ exponent
.
Then the values for each step are:
pwm_dim_levels[0] = 0
pwm_dim_levels[1] = 1
pwm_dim_levels[2] = 9
pwm_dim_levels[3] = 30
pwm_dim_levels[4] = 72
pwm_dim_levels[5] = 145
pwm_dim_levels[6] = 255
from led_strip.
Thanks @seanlano!
I was had intended to insert a mapping shim method - pass a function a value from 0-100 and then have it return a non linear value from 0-100. Something like what you've proposed ought to work well!
Looking forward to seeing your LED controller in the flesh... :)
from led_strip.
Related Issues (13)
- Debouncing needs to be handled HOT 1
- No silk screen annotations on connectors
- No LEDs on board
- Debounce resistors too high HOT 2
- Add PIR to the system
- Need better control over LED strips on startup HOT 2
- Fade should look better for lower brightness settings HOT 1
- Pull-downs on FET driver lines required
- Only listen to rotary encoder when LED strip is on HOT 1
- Fades should be able to be interrupted HOT 3
- led_strip_breadboard.fzz: Unable to find part HOT 5
- main.py: LED strip driving functions should be brought out into own class HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from led_strip.