1
+ /*
2
+ *******************************************************************************
3
+ * Copyright (c) 2022 by M5Stack
4
+ * Equipped with M5Core sample source code
5
+ * 配套 M5Core 示例源代码
6
+ * Visit the website for more information: https://docs.m5stack.com/zh_CN/products
7
+ * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/products
8
+ *
9
+ * Please follow the steps below to add FastLED library:
10
+ * - Arduino menu --> Manage Libraries... --> FastLED --> install
11
+ * 在烧录前请按以下步骤添加 FastLED 库:
12
+ * - Arduino menu --> Manage Libraries... --> FastLED --> install
13
+ *
14
+ * describe: KEY. 按键.
15
+ * date: 2022/6/1
16
+ *******************************************************************************
17
+ */
18
+
19
+ #include < M5Stack.h>
20
+ #include < FastLED.h>
21
+
22
+ uint8_t ledColor = 0 ;
23
+
24
+ #define KEY_PIN 36
25
+ #define DATA_PIN 26
26
+
27
+ CRGB LED[1 ];
28
+
29
+ void setup () {
30
+ M5.begin ();
31
+ M5.Lcd .setTextSize (3 );
32
+ M5.Lcd .print (" \n UNIT-KEY Example\n\n Key State:" );
33
+ /* Init key pin */
34
+ pinMode (KEY_PIN, INPUT_PULLUP);
35
+ /* Init RGB led */
36
+ FastLED.addLeds <SK6812, DATA_PIN, GRB>(LED, 1 );
37
+ LED[0 ] = CRGB::Blue;
38
+ FastLED.setBrightness (0 );
39
+ }
40
+
41
+ void loop () {
42
+ /* If Key was pressed */
43
+ if (!digitalRead (KEY_PIN)) {
44
+ M5.Lcd .setCursor (75 , 130 );
45
+ M5.Lcd .print ((" Pressed " ));
46
+ FastLED.setBrightness (255 );
47
+ FastLED.show ();
48
+ /* Hold until the key released */
49
+ while (!digitalRead (KEY_PIN))
50
+ ;
51
+ } else {
52
+ M5.Lcd .setCursor (75 , 130 );
53
+ M5.Lcd .println ((" Released" ));
54
+ FastLED.setBrightness (0 );
55
+ FastLED.show ();
56
+ }
57
+ delay (100 );
58
+ }
0 commit comments