25
25
#define LEDC_FADE_TIME (2000 )
26
26
27
27
// gamma factor for mathematical calculation
28
- #define LEDC_GAMMA_FACTOR (2.6 )
28
+ #define LEDC_GAMMA_FACTOR (2.6 )
29
29
30
30
// use gamma LUT for better performance instead of mathematical calculation (gamma factor)
31
- #define USE_GAMMA_LUT 1
31
+ #define USE_GAMMA_LUT 1
32
32
33
33
// fade LED pins
34
34
const uint8_t ledPinR = 4 ;
@@ -42,17 +42,13 @@ bool fade_in = true;
42
42
// Custom Gamma LUT demonstration with 101 steps (Brightness 0 - 100% gamma correction look up table (gamma = 2.6))
43
43
// Y = B ^ 2.6 - Pre-computed LUT to save runtime computation
44
44
static const float ledcGammaLUT[101 ] = {
45
- 0.000000 , 0.000006 , 0.000038 , 0.000110 , 0.000232 , 0.000414 , 0.000666 , 0.000994 , 0.001406 , 0.001910 ,
46
- 0.002512 , 0.003218 , 0.004035 , 0.004969 , 0.006025 , 0.007208 , 0.008525 , 0.009981 , 0.011580 , 0.013328 ,
47
- 0.015229 , 0.017289 , 0.019512 , 0.021902 , 0.024465 , 0.027205 , 0.030125 , 0.033231 , 0.036527 , 0.040016 ,
48
- 0.043703 , 0.047593 , 0.051688 , 0.055993 , 0.060513 , 0.065249 , 0.070208 , 0.075392 , 0.080805 , 0.086451 ,
49
- 0.092333 , 0.098455 , 0.104821 , 0.111434 , 0.118298 , 0.125416 , 0.132792 , 0.140428 , 0.148329 , 0.156498 ,
50
- 0.164938 , 0.173653 , 0.182645 , 0.191919 , 0.201476 , 0.211321 , 0.221457 , 0.231886 , 0.242612 , 0.253639 ,
51
- 0.264968 , 0.276603 , 0.288548 , 0.300805 , 0.313378 , 0.326268 , 0.339480 , 0.353016 , 0.366879 , 0.381073 ,
52
- 0.395599 , 0.410461 , 0.425662 , 0.441204 , 0.457091 , 0.473325 , 0.489909 , 0.506846 , 0.524138 , 0.541789 ,
53
- 0.559801 , 0.578177 , 0.596920 , 0.616032 , 0.635515 , 0.655374 , 0.675610 , 0.696226 , 0.717224 , 0.738608 ,
54
- 0.760380 , 0.782542 , 0.805097 , 0.828048 , 0.851398 , 0.875148 , 0.899301 , 0.923861 , 0.948829 , 0.974208 ,
55
- 1.000000 ,
45
+ 0.000000 , 0.000006 , 0.000038 , 0.000110 , 0.000232 , 0.000414 , 0.000666 , 0.000994 , 0.001406 , 0.001910 , 0.002512 , 0.003218 , 0.004035 , 0.004969 , 0.006025 ,
46
+ 0.007208 , 0.008525 , 0.009981 , 0.011580 , 0.013328 , 0.015229 , 0.017289 , 0.019512 , 0.021902 , 0.024465 , 0.027205 , 0.030125 , 0.033231 , 0.036527 , 0.040016 ,
47
+ 0.043703 , 0.047593 , 0.051688 , 0.055993 , 0.060513 , 0.065249 , 0.070208 , 0.075392 , 0.080805 , 0.086451 , 0.092333 , 0.098455 , 0.104821 , 0.111434 , 0.118298 ,
48
+ 0.125416 , 0.132792 , 0.140428 , 0.148329 , 0.156498 , 0.164938 , 0.173653 , 0.182645 , 0.191919 , 0.201476 , 0.211321 , 0.221457 , 0.231886 , 0.242612 , 0.253639 ,
49
+ 0.264968 , 0.276603 , 0.288548 , 0.300805 , 0.313378 , 0.326268 , 0.339480 , 0.353016 , 0.366879 , 0.381073 , 0.395599 , 0.410461 , 0.425662 , 0.441204 , 0.457091 ,
50
+ 0.473325 , 0.489909 , 0.506846 , 0.524138 , 0.541789 , 0.559801 , 0.578177 , 0.596920 , 0.616032 , 0.635515 , 0.655374 , 0.675610 , 0.696226 , 0.717224 , 0.738608 ,
51
+ 0.760380 , 0.782542 , 0.805097 , 0.828048 , 0.851398 , 0.875148 , 0.899301 , 0.923861 , 0.948829 , 0.974208 , 1.000000 ,
56
52
};
57
53
#endif
58
54
@@ -69,13 +65,12 @@ void setup() {
69
65
ledcAttach (ledPinG, LEDC_BASE_FREQ, LEDC_TIMER_12_BIT);
70
66
ledcAttach (ledPinB, LEDC_BASE_FREQ, LEDC_TIMER_12_BIT);
71
67
72
-
73
- #if USE_GAMMA_LUT // Use default gamma LUT for better performance
68
+ #if USE_GAMMA_LUT // Use default gamma LUT for better performance
74
69
ledcSetGammaTable (ledcGammaLUT, 101 );
75
70
#else // Use mathematical gamma correction (default, more flexible)
76
- ledcSetGammaFactor (LEDC_GAMMA_FACTOR); // This is optional to set custom gamma factor (default is 2.8)
71
+ ledcSetGammaFactor (LEDC_GAMMA_FACTOR); // This is optional to set custom gamma factor (default is 2.8)
77
72
#endif
78
-
73
+
79
74
// Setup and start gamma curve fade on led (duty from 0 to 4095)
80
75
ledcFadeGamma (ledPinR, LEDC_START_DUTY, LEDC_TARGET_DUTY, LEDC_FADE_TIME);
81
76
ledcFadeGamma (ledPinG, LEDC_START_DUTY, LEDC_TARGET_DUTY, LEDC_FADE_TIME);
0 commit comments