Site Navigation

Your Account

Choose Language

Anything programming related to the Hexbright

34 Questions View all

How to select Arbitrary Values of Brightness?

What pins must be set to achieve arbitrary values of brightness? I'm looking for a linear increase in perceived brightness and can't figure out exactly how this can be done from the example code.

Answered! View the answer I have this problem too

Is this a good question?

Score 1


I was able to figure this out from my modifications to hexbright4. The Y value from the accelerometer determines if the flashlight is pointing to the ground, up in the sky, or directly in front of you. I changed the Knobbing section (which had previously confused me) to key off this value instead of a rotation about the z-axis.

analogWrite(DPIN_DRV_EN, value);

where value is from 0 (off) to 255 (max) controls this.


Add a comment

1 Answer

Chosen Solution

You are correct, that is how you set the brightness.

The Problem

As for a perceptually linear approximation, it's not exactly simple. First off, we perceive a linear increase in lumens as being less bright. The relationship is approximately exponential (or square/cube power), but it's not known. Second off, we're basically setting the cree led's power consumption, not its output in lumens - and it's more efficient at different power levels. So, that's not linear, either.

Because of the way we perceive light, adjacent power values quite low are very easily perceived. So, in doing a linear mapping, small changes at a low brightnesses are perceived as being large. In order to make this linear, we get an area where we increase the perceived value, but nothing actually changes, or we suddenly get a large step.

An Implementation

I think I've done a pretty good job in this library.

libraries/hexbright/hexbright.cpp has an approximation algorithm, search for set_light_level

programs/linearity_test has the code I used to find that particular algorithm.

I welcome any input you may have!

Was this answer helpful?

Score 1
Add a comment

Add your answer

Zeke Tamayo will be eternally grateful.