mirror of
https://github.com/m5stack/M5Stack.git
synced 2026-05-20 10:06:46 -07:00
op,relay
This commit is contained in:
@@ -1,25 +1,30 @@
|
||||
/*
|
||||
Description: Detect the current OP 90/180 Unit Photoelectric switch status.
|
||||
*******************************************************************************
|
||||
* Copyright (c) 2021 by M5Stack
|
||||
* Equipped with M5Core sample source code
|
||||
* 配套 M5Core 示例源代码
|
||||
* Visit the website for more information:https://docs.m5stack.com/en/core/gray
|
||||
* 获取更多资料请访问:https://docs.m5stack.com/zh_CN/core/gray
|
||||
*
|
||||
* describe:OP 180/90. 非接触式光电限位开关
|
||||
* date:2021/8/11
|
||||
*******************************************************************************
|
||||
Please connect to Port B(36),Detect the current OP 90/180 Unit Photoelectric switch status.
|
||||
请连接端口B(36),检测当前OP 90/180单元光电开关状态。
|
||||
*/
|
||||
|
||||
#include <M5Stack.h>
|
||||
|
||||
|
||||
void setup() {
|
||||
// put your setup code here, to run once:
|
||||
M5.begin();
|
||||
M5.Power.begin();
|
||||
//Wire.begin();
|
||||
M5.Lcd.setCursor(120, 10, 4);
|
||||
M5.begin(); //Init M5Stack. 初始化M5Stack
|
||||
M5.Power.begin(); //Init power 初始化电源模块
|
||||
M5.lcd.setTextSize(2); //Set the text size to 2. 设置文字大小为2
|
||||
M5.Lcd.setCursor(80, 10); //Set the cursor at (80,10). 将光标设置在(80,10)处
|
||||
M5.Lcd.println("90/180 OPTICAL");
|
||||
|
||||
pinMode(36,INPUT_PULLUP);
|
||||
|
||||
pinMode(36,INPUT_PULLUP); //Set pin 36 to input pull-up mode. 设置36号引脚为输入上拉模式
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// put your main code here, to run repeatedly:
|
||||
M5.Lcd.setCursor(80, 120, 4);
|
||||
M5.Lcd.printf("ir receive: %d",digitalRead(36));
|
||||
|
||||
M5.Lcd.setCursor(80, 120);
|
||||
M5.Lcd.printf("IR Receive: %d",digitalRead(36)); //Output the value of pin 36. 输出36号引脚的值
|
||||
}
|
||||
|
||||
@@ -1,24 +1,38 @@
|
||||
/*
|
||||
Description: Use RELAY to switch on and off the circuit.
|
||||
*******************************************************************************
|
||||
* Copyright (c) 2021 by M5Stack
|
||||
* Equipped with M5Core sample source code
|
||||
* 配套 M5Core 示例源代码
|
||||
* Visit the website for more information:https://docs.m5stack.com/en/core/gray
|
||||
* 获取更多资料请访问:https://docs.m5stack.com/zh_CN/core/gray
|
||||
*
|
||||
* describe:Relay. 继电器
|
||||
* date:2021/8/16
|
||||
*******************************************************************************
|
||||
Please connect to Port B(26),Use RELAY to switch on and off the circuit.
|
||||
请连接端口B(26),使用继电器开关电路。
|
||||
*/
|
||||
|
||||
#include <M5Stack.h>
|
||||
|
||||
void setup() {
|
||||
M5.begin();
|
||||
M5.Power.begin();
|
||||
M5.Lcd.clear(BLACK);
|
||||
M5.Lcd.setTextFont(4);
|
||||
M5.Lcd.setTextColor(YELLOW, BLACK);
|
||||
M5.Lcd.setCursor(50, 0, 4);
|
||||
M5.begin(); //Init M5Stack. 初始化M5Stack
|
||||
M5.Power.begin(); //Init power 初始化电源模块
|
||||
M5.lcd.setTextSize(2); //Set the text size to 2. 设置文字大小为2
|
||||
M5.Lcd.setCursor(50, 0);
|
||||
M5.Lcd.println(("Relay Example"));
|
||||
//disable the speak noise
|
||||
dacWrite(25, 0);
|
||||
dacWrite(25, 0); //disable the speak noise
|
||||
pinMode(26, OUTPUT);
|
||||
}
|
||||
|
||||
void loop(void) {
|
||||
M5.Lcd.setCursor(100, 40);
|
||||
M5.Lcd.print("ON");
|
||||
digitalWrite(26, HIGH);
|
||||
delay(500);
|
||||
delay(1000);
|
||||
M5.Lcd.fillRect(100,40,60,50,BLACK);
|
||||
M5.Lcd.print("OFF");
|
||||
digitalWrite(26, LOW);
|
||||
delay(500);
|
||||
delay(1000);
|
||||
M5.Lcd.fillRect(100,40,60,50,BLACK);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user