/
IR.ino
52 lines (47 loc) · 1.85 KB
/
IR.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
*******************************************************************************
* Copyright (c) 2023 by M5Stack
* Equipped with M5StickC sample source code
* 配套 M5StickC 示例源代码
* Visit for more information: https://docs.m5stack.com/en/unit/ir
* 获取更多资料请访问: https://docs.m5stack.com/zh_CN/unit/ir
*
* Product: ir.
* Date: 2021/8/27
*******************************************************************************
Please connect to Port B,Use IR Unit to receive and test infrared receiving
and transmitting 请连接端口B,使用红外单元接收和测试红外接收和发射.
*/
#include <M5StickC.h>
int ir_recv_pin = 33; // set the input pin. 设置引脚
int ir_send_pin = 32;
int last_recv_value = 0;
int cur_recv_value = 0;
void setup() {
M5.begin();
pinMode(ir_recv_pin, INPUT);
pinMode(ir_send_pin, OUTPUT);
// send infrared light. 发送红外线
// now, you can see the infrared light through mobile phone camera.
// 现在,你可以通过手机摄像头看到红外光
digitalWrite(ir_send_pin, 1);
M5.Lcd.setTextSize(2);
M5.Lcd.setCursor(0, 0);
M5.Lcd.print("Test for IR receiver: ");
}
void loop() {
// now, once you press the button on a remote controller to send infrared
// light. 现在,一旦你按下遥控器上的按钮发送红外线 the screen will display
// "detected!" 屏幕将显示“检测到!”
cur_recv_value = digitalRead(ir_recv_pin);
if (last_recv_value != cur_recv_value) {
M5.Lcd.setCursor(0, 25);
M5.Lcd.fillRect(0, 25, 150, 25, BLACK);
if (cur_recv_value ==
0) { // 0: detected 1: not detected, 0检测到,1没有检测到
M5.Lcd.print("detected!");
}
last_recv_value = cur_recv_value;
}
Serial.println(cur_recv_value);
}