Skip to content

Commit be6f34b

Browse files
committed
LIGHT Example
1 parent fbc2732 commit be6f34b

File tree

1 file changed

+24
-18
lines changed

1 file changed

+24
-18
lines changed

examples/Unit/LIGHT/LIGHT.ino

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,37 @@
77
* 获取更多资料请访问:https://docs.m5stack.com/zh_CN/core/gray
88
*
99
* describe: Light. 环境光传感器
10-
* date:2021/8/18
10+
* date:2022/2/13
1111
*******************************************************************************
12-
Please connect to Port B,Use the Light Unit screen to display the current ambient lighting value
13-
请连接端口 B ,使用Light Unit 屏幕显示当前环境光照值。
12+
Please connect to Port B,Use the Light Unit screen to display the current
13+
ambient lighting value 请连接端口 B ,使用Light Unit 屏幕显示当前环境光照值。
1414
*/
1515

1616
#include <M5Stack.h>
1717

18+
TFT_eSprite img = TFT_eSprite(&M5.Lcd);
19+
1820
void setup() {
19-
M5.begin(); //Init M5Stack. 初始化M5Stack
20-
M5.Power.begin(); //Init power 初始化电源模块
21-
M5.lcd.setTextSize(2); //Set the text size to 2. 设置文字大小为2
22-
M5.Lcd.printf("UNIT_LIGHT EXAMPLE\n\n");
23-
M5.Lcd.println("Analog:");
24-
M5.Lcd.println("Digital:");
25-
pinMode(26, INPUT); //Set pin 26 as input mode. 设置引脚26为输入模式
21+
M5.begin(); // Init M5Stack. 初始化M5Stack
22+
M5.Power.begin(); // Init power 初始化电源模块
23+
img.setColorDepth(8);
24+
img.createSprite(320, 240); //创建一块320x240的画布
25+
img.setTextSize(2);
26+
pinMode(26, INPUT); // Set pin 26 as input mode. 设置引脚26为输入模式
2627
}
2728

2829
void loop() {
29-
static uint16_t digitalRead_value = 0, analogRead_value = 0;
30-
analogRead_value = analogRead(36); //Store the analog quantity read from pin 36. 将36号引脚读取到的模拟量存储
31-
digitalRead_value = digitalRead(26); //Store the number read from pin 26. 将26号引脚读取到的数字量存储
32-
M5.Lcd.setCursor(90, 30);
33-
M5.Lcd.printf("%d\n", analogRead_value);
34-
M5.Lcd.setCursor(90, 50);
35-
M5.Lcd.printf("%d\n", digitalRead_value);
36-
delay(10);
30+
static uint16_t digitalRead_value = 0, analogRead_value = 0;
31+
analogRead_value = analogRead(36); // Store the analog quantity read from
32+
// pin 36. 将36号引脚读取到的模拟量存储
33+
digitalRead_value = digitalRead(
34+
26); // Store the number read from pin 26. 将26号引脚读取到的数字量存储
35+
img.fillRect(0, 0, 320, 240, 0x00);
36+
img.drawString("UNIT_LIGHT EXAMPLE", 40, 0);
37+
img.setCursor(90, 30);
38+
img.printf("Analog:%d\n", analogRead_value);
39+
img.setCursor(90, 50);
40+
img.printf("Digital:%d\n", digitalRead_value);
41+
img.pushSprite(0, 0); //把画布推送到屏幕(0,0)处
42+
delay(10);
3743
}

0 commit comments

Comments
 (0)