1
1
/*
2
- * SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD
2
+ * SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD
3
3
*
4
4
* SPDX-License-Identifier: MIT
5
5
*/
6
6
7
7
/*
8
8
* @file button.ino
9
9
* @author tinyu (tinyu@m5stack.com)
10
- * @brief M5CoreS3 Touch Test
11
- * @version 0.1
12
- * @date 2024-06 -07
10
+ * @brief M5CoreS3 Touch Button / PWR Button Test
11
+ * @version 0.2
12
+ * @date 2025-03 -07
13
13
*
14
14
*
15
15
* @Hardwares: M5CoreS3
16
- * @Platform Version: Arduino M5Stack Board Manager v2.0.9
16
+ * @Platform Version: Arduino M5Stack Board Manager v2.1.3
17
17
* @Dependent Library:
18
18
* M5GFX: https://github.com/m5stack/M5GFX
19
19
* M5Unified: https://github.com/m5stack/M5Unified
24
24
25
25
static m5::touch_state_t prev_state;
26
26
27
- void setup (void ) {
27
+ void setup (void )
28
+ {
28
29
auto cfg = M5.config ();
29
30
CoreS3.begin (cfg);
30
31
@@ -33,42 +34,36 @@ void setup(void) {
33
34
CoreS3.Display .setFont (&fonts::Orbitron_Light_24);
34
35
CoreS3.Display .setTextSize (1 );
35
36
36
- CoreS3.Display .drawString (" Touch Button Test" , CoreS3.Display .width () / 2 ,
37
- 15 );
38
- CoreS3.Display .fillRect (0 , CoreS3.Display .height () - 40 ,
39
- CoreS3.Display .width () / 3 , 40 , WHITE);
40
- CoreS3.Display .fillRect (CoreS3.Display .width () / 3 ,
41
- CoreS3.Display .height () - 40 ,
42
- CoreS3.Display .width () / 3 , 40 , GREEN);
43
- CoreS3.Display .fillRect ((CoreS3.Display .width () / 3 ) * 2 ,
44
- CoreS3.Display .height () - 40 ,
45
- CoreS3.Display .width () / 3 , 40 , YELLOW);
46
- CoreS3.Display .drawString (" Btn A Btn B Btn C" ,
47
- CoreS3.Display .width () / 2 ,
48
- CoreS3.Display .height () - 20 );
37
+ CoreS3.Display .drawString (" Touch Button Test" , CoreS3.Display .width () / 2 , 15 );
38
+ CoreS3.Display .fillRect (0 , CoreS3.Display .height () - 40 , CoreS3.Display .width () / 3 , 40 , WHITE);
39
+ CoreS3.Display .fillRect (CoreS3.Display .width () / 3 , CoreS3.Display .height () - 40 , CoreS3.Display .width () / 3 , 40 ,
40
+ GREEN);
41
+ CoreS3.Display .fillRect ((CoreS3.Display .width () / 3 ) * 2 , CoreS3.Display .height () - 40 , CoreS3.Display .width () / 3 ,
42
+ 40 , YELLOW);
43
+ CoreS3.Display .drawString (" Btn A Btn B Btn C" , CoreS3.Display .width () / 2 , CoreS3.Display .height () - 20 );
49
44
}
50
45
51
- void loop (void ) {
46
+ void loop (void )
47
+ {
52
48
CoreS3.update ();
53
49
auto touchPoint = CoreS3.Touch .getDetail ();
54
50
if (prev_state != touchPoint.state ) {
55
51
prev_state = touchPoint.state ;
56
52
}
57
- if ((CoreS3.Display .height () > touchPoint.y &&
58
- touchPoint.y > CoreS3.Display .height () - 40 ) &&
53
+ if ((CoreS3.Display .height () > touchPoint.y && touchPoint.y > CoreS3.Display .height () - 40 ) &&
59
54
touchPoint.state == m5::touch_state_t ::touch_begin) {
60
55
CoreS3.Display .fillRect (0 , 40 , CoreS3.Display .width (), 70 , BLACK);
61
56
if (CoreS3.Display .width () / 3 > touchPoint.x && touchPoint.x > 0 )
62
- CoreS3.Display .drawString (" Btn A" , CoreS3.Display .width () / 2 ,
63
- CoreS3.Display .height () / 2 - 30 );
64
- if ((CoreS3.Display .width () / 3 ) * 2 > touchPoint.x &&
65
- touchPoint.x > CoreS3.Display .width () / 3 )
66
- CoreS3.Display .drawString (" Btn B" , CoreS3.Display .width () / 2 ,
67
- CoreS3.Display .height () / 2 - 30 );
68
- if (CoreS3.Display .width () > touchPoint.x &&
69
- touchPoint.x > (CoreS3.Display .width () / 3 ) * 2 )
70
- CoreS3.Display .drawString (" Btn C" , CoreS3.Display .width () / 2 ,
71
- CoreS3.Display .height () / 2 - 30 );
57
+ CoreS3.Display .drawString (" Btn A" , CoreS3.Display .width () / 2 , CoreS3.Display .height () / 2 - 30 );
58
+ if ((CoreS3.Display .width () / 3 ) * 2 > touchPoint.x && touchPoint.x > CoreS3.Display .width () / 3 )
59
+ CoreS3.Display .drawString (" Btn B" , CoreS3.Display .width () / 2 , CoreS3.Display .height () / 2 - 30 );
60
+ if (CoreS3.Display .width () > touchPoint.x && touchPoint.x > (CoreS3.Display .width () / 3 ) * 2 )
61
+ CoreS3.Display .drawString (" Btn C" , CoreS3.Display .width () / 2 , CoreS3.Display .height () / 2 - 30 );
72
62
Serial.printf (" x:%d ,y:%d" , touchPoint.x , touchPoint.y );
73
63
}
64
+ int state = M5.BtnPWR .wasClicked ();
65
+ if (state) {
66
+ CoreS3.Display .fillRect (0 , 40 , CoreS3.Display .width (), 70 , BLACK);
67
+ CoreS3.Display .drawString (" Btn PWR" , CoreS3.Display .width () / 2 , CoreS3.Display .height () / 2 - 30 );
68
+ }
74
69
}
0 commit comments