@@ -23,12 +23,23 @@ static unsigned long long msSinceMidnight()
23
23
24
24
void dimmerTask (void *parameter)
25
25
{
26
- constexpr const uint8_t ledPin[NUMBER_OF_CHANNELS] = {38 , 39 , 40 , 41 , 42 };
27
- constexpr const float fullMoonLevel[NUMBER_OF_CHANNELS] = {0 , 0 , 0 , 0 , 0.06 };
26
+ static constexpr const uint8_t ledPin[NUMBER_OF_CHANNELS] =
27
+ {LEDPIN_0, LEDPIN_1, LEDPIN_2, LEDPIN_3, LEDPIN_4};
28
+ static constexpr const float fullMoonLevel[NUMBER_OF_CHANNELS] =
29
+ {0 , 0 , 0 , 0 , 0.06 };
30
+ static constexpr const int PWM_BITDEPTH = min (SOC_LEDC_TIMER_BIT_WIDTH, 16 );
31
+ static constexpr const int LEDC_MAX_VALUE = (1 << PWM_BITDEPTH) - 1 ;
32
+ static constexpr const int freq = 1220 ;
33
+
34
+ #ifdef LGFX_M5STACK
35
+ static constexpr const int BACKLIGHT_PIN = 32 ;
36
+ if (!ledcChangeFrequency (BACKLIGHT_PIN, freq, PWM_BITDEPTH) ||
37
+ !ledcWrite (BACKLIGHT_PIN, LEDC_MAX_VALUE >> 6 ))
38
+ log_w (" Could not capture M5Stack backlight" );
39
+ #endif
28
40
29
- const int freq = 1200 ;
30
41
for (int index = 0 ; index < NUMBER_OF_CHANNELS; index++)
31
- if (!ledcAttachChannel (ledPin[index], freq, SOC_LEDC_TIMER_BIT_WIDTH , index + 2 ))
42
+ if (!ledcAttachChannel (ledPin[index], freq, PWM_BITDEPTH , index + 2 ))
32
43
{
33
44
log_e (" Error setting ledc pin %i. system halted" , index);
34
45
while (1 )
@@ -80,7 +91,6 @@ void dimmerTask(void *parameter)
80
91
81
92
currentPercentage[index] = newPercentage < currentMoonLevel ? currentMoonLevel : newPercentage;
82
93
83
- constexpr const int LEDC_MAX_VALUE = (1 << SOC_LEDC_TIMER_BIT_WIDTH) - 1 ;
84
94
const int dutyCycle = mapf (currentPercentage[index], 0 , 100 , 0 , LEDC_MAX_VALUE);
85
95
86
96
if (!ledcWrite (ledPin[index], dutyCycle))
@@ -99,7 +109,7 @@ void dimmerTask(void *parameter)
99
109
lastLcdRefresh = millis ();
100
110
}
101
111
102
- constexpr const int MOON_UPDATE_INTERVAL_SECONDS = 1 ;
112
+ constexpr const int MOON_UPDATE_INTERVAL_SECONDS = 5 ;
103
113
static time_t lastMoonUpdate = time (NULL );
104
114
if (time (NULL ) - lastMoonUpdate >= MOON_UPDATE_INTERVAL_SECONDS)
105
115
{
@@ -113,16 +123,16 @@ void dimmerTask(void *parameter)
113
123
msg.int1 = moon.angle ;
114
124
xQueueSend (lcdQueue, &msg, portMAX_DELAY);
115
125
}
116
- /*
117
- static int lps = 0;
118
- lps++;
119
- static time_t lastlps = time(NULL);
120
- if (time(NULL) != lastlps)
121
- {
122
- log_i("loops per second: %i", lps);
123
- lastlps++;
124
- lps = 0;
125
- }
126
- */
126
+ /*
127
+ static int lps = 0;
128
+ lps++;
129
+ static time_t lastlps = time(NULL);
130
+ if (time(NULL) != lastlps)
131
+ {
132
+ log_i("loops per second: %i", lps);
133
+ lastlps++;
134
+ lps = 0;
135
+ }
136
+ */
127
137
}
128
138
}
0 commit comments