@@ -27,7 +27,7 @@ void setup() {
27
27
// while (!Serial);
28
28
Serial.begin (115200 );
29
29
delay (100 );
30
-
30
+
31
31
pixels.begin (); // Initialize pins for output
32
32
pixels.show (); // Turn all LEDs off ASAP
33
33
pixels.setBrightness (20 );
@@ -37,7 +37,7 @@ void setup() {
37
37
pinMode (BUTTON_UP, INPUT_PULLDOWN);
38
38
39
39
// analogReadResolution(13);
40
-
40
+
41
41
tft.init (240 , 240 ); // Initialize ST7789 screen
42
42
pinMode (TFT_BACKLIGHT, OUTPUT);
43
43
digitalWrite (TFT_BACKLIGHT, HIGH); // Backlight on
@@ -52,8 +52,8 @@ void setup() {
52
52
tft.setTextColor (ST77XX_YELLOW);
53
53
tft.print (" DP310? " );
54
54
55
-
56
- if (! dps.begin_I2C ()) {
55
+
56
+ if (! dps.begin_I2C ()) {
57
57
tft.setTextColor (ST77XX_RED);
58
58
tft.println (" FAIL!" );
59
59
while (1 ) delay (100 );
@@ -67,8 +67,8 @@ void setup() {
67
67
tft.setCursor (0 , 20 );
68
68
tft.setTextColor (ST77XX_YELLOW);
69
69
tft.print (" AHT20? " );
70
-
71
- if (! aht.begin ()) {
70
+
71
+ if (! aht.begin ()) {
72
72
tft.setTextColor (ST77XX_RED);
73
73
tft.println (" FAIL!" );
74
74
while (1 ) delay (100 );
@@ -79,12 +79,18 @@ void setup() {
79
79
pinMode (LED_BUILTIN, OUTPUT);
80
80
pinMode (SPEAKER, OUTPUT);
81
81
82
+ #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 1, 1)
83
+ ledcAttach (LED_BUILTIN, 2000 , 8 );
84
+ ledcAttach (SPEAKER, 2000 , 8 );
85
+ ledcWrite (SPEAKER, 0 );
86
+ #else
82
87
ledcSetup (0 , 2000 , 8 );
83
88
ledcAttachPin (LED_BUILTIN, 0 );
84
89
85
90
ledcSetup (1 , 2000 , 8 );
86
91
ledcAttachPin (SPEAKER, 1 );
87
92
ledcWrite (1 , 0 );
93
+ #endif
88
94
}
89
95
90
96
@@ -94,11 +100,11 @@ void loop() {
94
100
95
101
/* ******************** sensors */
96
102
sensors_event_t humidity, temp, pressure;
97
-
103
+
98
104
tft.setCursor (0 , 0 );
99
105
tft.setTextColor (ST77XX_YELLOW, BG_COLOR);
100
106
dps.getEvents (&temp, &pressure);
101
-
107
+
102
108
tft.print (" DP310: " );
103
109
tft.print (temp.temperature , 0 );
104
110
tft.print (" C " );
@@ -125,23 +131,23 @@ void loop() {
125
131
tft.setCursor (0 , 40 );
126
132
tft.setTextColor (ST77XX_YELLOW);
127
133
tft.print (" Buttons: " );
128
- if (! digitalRead (BUTTON_DOWN)) {
134
+ if (! digitalRead (BUTTON_DOWN)) {
129
135
tft.setTextColor (ST77XX_GREY);
130
136
} else {
131
137
Serial.println (" DOWN pressed" );
132
138
tft.setTextColor (ST77XX_WHITE);
133
139
}
134
140
tft.print (" DOWN " );
135
141
136
- if (! digitalRead (BUTTON_SELECT)) {
142
+ if (! digitalRead (BUTTON_SELECT)) {
137
143
tft.setTextColor (ST77XX_GREY);
138
144
} else {
139
145
Serial.println (" SELECT pressed" );
140
146
tft.setTextColor (ST77XX_WHITE);
141
147
}
142
148
tft.print (" SEL " );
143
-
144
- if (! digitalRead (BUTTON_UP)) {
149
+
150
+ if (! digitalRead (BUTTON_UP)) {
145
151
tft.setTextColor (ST77XX_GREY);
146
152
} else {
147
153
Serial.println (" UP pressed" );
@@ -151,25 +157,25 @@ void loop() {
151
157
152
158
/* ************************* CAPACITIVE */
153
159
uint16_t touchread;
154
-
160
+
155
161
tft.setCursor (0 , 60 );
156
162
tft.setTextColor (ST77XX_YELLOW, BG_COLOR);
157
163
tft.print (" Captouch 6: " );
158
164
touchread = touchRead (6 );
159
- if (touchread < 10000 ) {
165
+ if (touchread < 10000 ) {
160
166
tft.setTextColor (ST77XX_GREY, BG_COLOR);
161
167
} else {
162
168
tft.setTextColor (ST77XX_WHITE, BG_COLOR);
163
169
}
164
170
tft.print (touchread);
165
171
tft.println (" " );
166
172
Serial.printf (" Captouch #6 reading: %d\n " , touchread);
167
-
173
+
168
174
tft.setCursor (0 , 80 );
169
175
tft.setTextColor (ST77XX_YELLOW, BG_COLOR);
170
176
tft.print (" Captouch 7: " );
171
177
touchread = touchRead (7 );
172
- if (touchread < 20000 ) {
178
+ if (touchread < 20000 ) {
173
179
tft.setTextColor (ST77XX_GREY, BG_COLOR);
174
180
} else {
175
181
tft.setTextColor (ST77XX_WHITE, BG_COLOR);
@@ -183,7 +189,7 @@ void loop() {
183
189
tft.setTextColor (ST77XX_YELLOW, BG_COLOR);
184
190
tft.print (" Captouch 8: " );
185
191
touchread = touchRead (8 );
186
- if (touchread < 20000 ) {
192
+ if (touchread < 20000 ) {
187
193
tft.setTextColor (ST77XX_GREY, BG_COLOR);
188
194
} else {
189
195
tft.setTextColor (ST77XX_WHITE, BG_COLOR);
@@ -200,7 +206,7 @@ void loop() {
200
206
tft.setTextColor (ST77XX_YELLOW, BG_COLOR);
201
207
tft.print (" Analog 0: " );
202
208
analogread = analogRead (A0);
203
- if (analogread < 8000 ) {
209
+ if (analogread < 8000 ) {
204
210
tft.setTextColor (ST77XX_WHITE, BG_COLOR);
205
211
} else {
206
212
tft.setTextColor (ST77XX_RED, BG_COLOR);
@@ -214,7 +220,7 @@ void loop() {
214
220
tft.setTextColor (ST77XX_YELLOW, BG_COLOR);
215
221
tft.print (" Analog 1: " );
216
222
analogread = analogRead (A1);
217
- if (analogread < 8000 ) {
223
+ if (analogread < 8000 ) {
218
224
tft.setTextColor (ST77XX_WHITE, BG_COLOR);
219
225
} else {
220
226
tft.setTextColor (ST77XX_RED, BG_COLOR);
@@ -223,12 +229,12 @@ void loop() {
223
229
tft.println (" " );
224
230
Serial.printf (" Analog A1 reading: %d\n " , analogread);
225
231
226
-
232
+
227
233
tft.setCursor (0 , 160 );
228
234
tft.setTextColor (ST77XX_YELLOW, BG_COLOR);
229
235
tft.print (" Analog 2: " );
230
236
analogread = analogRead (A2);
231
- if (analogread < 8000 ) {
237
+ if (analogread < 8000 ) {
232
238
tft.setTextColor (ST77XX_WHITE, BG_COLOR);
233
239
} else {
234
240
tft.setTextColor (ST77XX_RED, BG_COLOR);
@@ -245,21 +251,25 @@ void loop() {
245
251
tft.print (analogread);
246
252
tft.println (" " );
247
253
Serial.printf (" Light sensor reading: %d\n " , analogread);
248
-
254
+
249
255
/* ************************* Beep! */
250
- if (digitalRead (BUTTON_SELECT)) {
256
+ if (digitalRead (BUTTON_SELECT)) {
251
257
Serial.println (" ** Beep! ***" );
252
258
fhtone (SPEAKER, 988.0 , 100.0 ); // tone1 - B5
253
259
fhtone (SPEAKER, 1319.0 , 200.0 ); // tone2 - E6
254
260
delay (100 );
255
261
// fhtone(SPEAKER, 2000.0, 100.0);
256
262
}
257
-
263
+
258
264
/* ************************* LEDs */
259
265
// pulse red LED
266
+ #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 1, 1)
267
+ ledcWrite (LED_BUILTIN, LED_dutycycle);
268
+ #else
260
269
ledcWrite (0 , LED_dutycycle);
270
+ #endif
261
271
LED_dutycycle += 32 ;
262
-
272
+
263
273
// rainbow dotstars
264
274
for (int i=0 ; i<pixels.numPixels (); i++) { // For each pixel in strip...
265
275
int pixelHue = firstPixelHue + (i * 65536L / pixels.numPixels ());
@@ -271,9 +281,16 @@ void loop() {
271
281
272
282
273
283
void fhtone (uint8_t pin, float frequency, float duration) {
284
+ #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 1, 1)
285
+ ledcAttach (SPEAKER, frequency, 8 );
286
+ ledcWrite (SPEAKER, 128 );
287
+ delay (duration);
288
+ ledcWrite (SPEAKER, 0 );
289
+ #else
274
290
ledcSetup (1 , frequency, 8 );
275
291
ledcAttachPin (pin, 1 );
276
292
ledcWrite (1 , 128 );
277
293
delay (duration);
278
294
ledcWrite (1 , 0 );
295
+ #endif
279
296
}
0 commit comments