|
7 | 7 | * 获取更多资料请访问:https://docs.m5stack.com/zh_CN/core/gray
|
8 | 8 | *
|
9 | 9 | * describe: Light. 环境光传感器
|
10 |
| -* date:2021/8/18 |
| 10 | +* date:2022/2/13 |
11 | 11 | *******************************************************************************
|
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 屏幕显示当前环境光照值。 |
14 | 14 | */
|
15 | 15 |
|
16 | 16 | #include <M5Stack.h>
|
17 | 17 |
|
| 18 | +TFT_eSprite img = TFT_eSprite(&M5.Lcd); |
| 19 | + |
18 | 20 | 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为输入模式 |
26 | 27 | }
|
27 | 28 |
|
28 | 29 | 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); |
37 | 43 | }
|
0 commit comments