Skip to content

Commit 6bb51d3

Browse files
committed
add example Unit-Glass
1 parent 962c253 commit 6bb51d3

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

examples/Unit/GLASS/GLASS.ino

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
*******************************************************************************
3+
* Copyright (c) 2023 by M5Stack
4+
* Equipped with M5Core sample source code
5+
* 配套 M5Core 示例源代码
6+
* Visit for more information: https://docs.m5stack.com/en/core/gray
7+
* 获取更多资料请访问: https://docs.m5stack.com/zh_CN/core/gray
8+
*
9+
* Describe: Glass.
10+
* Date: 2023/2/23
11+
*******************************************************************************
12+
*/
13+
#include <M5Stack.h>
14+
#include <UNIT_GLASS.h>
15+
16+
UNIT_GLASS Glass;
17+
String string_buffer;
18+
19+
void setup() {
20+
M5.begin(1, 0, 1, 0);
21+
M5.Lcd.setTextSize(3);
22+
M5.Lcd.setTextColor(0x867D);
23+
M5.Lcd.printf(" Unit Glass Demo\n\n\n");
24+
M5.Lcd.printf(" Please connect\n\n your Unit-Glass\n\n");
25+
M5.Lcd.printf(" to PORT-A\n\n <--");
26+
27+
/* Unit-Glass init */
28+
Glass.begin(&Wire, GLASS_ADDR, 21, 22, 100000UL);
29+
Glass.invert(0);
30+
Glass.color_invert(0);
31+
Glass.clear();
32+
33+
/* Draw title on Unit-Glass */
34+
string_buffer = "M5STACK";
35+
Glass.set_string_buffer(string_buffer.c_str());
36+
Glass.draw_string(36, 0, 16, 1);
37+
string_buffer = " 2023-02-24";
38+
Glass.set_string_buffer(string_buffer.c_str());
39+
Glass.draw_string(0, 24, 16, 1);
40+
Glass.show();
41+
}
42+
43+
void loop() {
44+
/* When key on Unit-Glass was pressed, update conut and print it out */
45+
static int count = 0;
46+
if (Glass.getKeyA() == 0) {
47+
Glass.setBuzzer(1500, 128);
48+
Glass.enable_buzz();
49+
delay(50);
50+
Glass.disable_buzz();
51+
count++;
52+
} else if (Glass.getKeyB() == 0) {
53+
Glass.setBuzzer(2300, 128);
54+
Glass.enable_buzz();
55+
delay(50);
56+
Glass.disable_buzz();
57+
count--;
58+
}
59+
60+
string_buffer = " Count: ";
61+
string_buffer += count;
62+
string_buffer += " ";
63+
Glass.set_string_buffer(string_buffer.c_str());
64+
Glass.draw_string(0, 48, 16, 1);
65+
Glass.show();
66+
}

0 commit comments

Comments
 (0)