This commit is contained in:
Tinyu
2021-08-09 17:00:32 +08:00
parent daf58a2852
commit 44a531cd28
4 changed files with 48 additions and 119 deletions
@@ -1,63 +0,0 @@
/*
*******************************************************************************
* Copyright (c) 2021 by M5Stack
* Equipped with M5Core sample source code
* 配套 M5Core 示例源代码
* Visit the website for more informationhttps://docs.m5stack.com/en/core/gray
* 获取更多资料请访问:https://docs.m5stack.com/zh_CN/core/gray
*
* describeButton_Two. 双按键
* date2021/8/9
*******************************************************************************
Please connect to Port A,Read the button status of BUTTON Unit and display it on the screen
请连接端口A,读取按键的状态并在显示屏上显示
*/
#include <M5Stack.h>
int last_value1 = 0,last_value2 = 0;
int cur_value1 = 0,cur_value2 = 0;
void setup() {
M5.begin(); //Init M5Stack. 初始化M5Stack
M5.Power.begin(); //Init power 初始化电源模块
pinMode(21, INPUT); //set pin mode to input.设置引脚模式为输入模式
pinMode(22, INPUT);
M5.Lcd.setTextColor(YELLOW); //Set the font color to yellow. 设置字体颜色为黄色
M5.Lcd.setTextSize(2); //Setting the Font size. 设置字号大小
M5.Lcd.setCursor(80, 0); //Set the cursor position to (80,0). 将光标位置设置为(80,0)
M5.Lcd.println("Button example");
M5.Lcd.setTextColor(WHITE);
}
void loop() {
cur_value1 = digitalRead(22); // read the value of BUTTON. 读取22号引脚的值
cur_value2 = digitalRead(21);
M5.Lcd.setCursor(90,25); M5.Lcd.print("Btn.1 Btn.2");
M5.Lcd.setCursor(0,45); M5.Lcd.print("Value: ");
M5.Lcd.setCursor(0,85); M5.Lcd.print("State: ");
if(cur_value1 != last_value1){
M5.Lcd.fillRect(85,45,75,85,BLACK); //Draw a black rectangle 75 by 85 at (85,45). 在(85,45)处绘制宽75,高85的黑色矩形
if(cur_value1==0){
M5.Lcd.setCursor(95,45); M5.Lcd.print("0"); // display the status
M5.Lcd.setCursor(95,85); M5.Lcd.print("pre");
}
else{
M5.Lcd.setCursor(95,45); M5.Lcd.print("1"); // display the status
M5.Lcd.setCursor(95,85); M5.Lcd.print("rel");
}
last_value1 = cur_value1;
}
if(cur_value2 != last_value2){
M5.Lcd.fillRect(170,45,75,85,BLACK);
if(cur_value2==0){
M5.Lcd.setCursor(185,45); M5.Lcd.print("0"); // display the status
M5.Lcd.setCursor(185,85); M5.Lcd.print("pre");
}
else{
M5.Lcd.setCursor(185,45); M5.Lcd.print("1"); // display the status
M5.Lcd.setCursor(185,85); M5.Lcd.print("rel");
}
last_value2 = cur_value2;
}
}
+47 -55
View File
@@ -1,71 +1,63 @@
/*
Description: Read the button status of DUAL BUTTON Unit and display it on the screen.
*******************************************************************************
* Copyright (c) 2021 by M5Stack
* Equipped with M5Core sample source code
* 配套 M5Core 示例源代码
* Visit the website for more informationhttps://docs.m5stack.com/en/core/gray
* 获取更多资料请访问:https://docs.m5stack.com/zh_CN/core/gray
*
* describeButton_Two. 双按键
* date2021/8/9
*******************************************************************************
Please connect to Port A,Read the button status of BUTTON Unit and display it on the screen
请连接端口A,读取按键的状态并在显示屏上显示
*/
#include <M5Stack.h>
int last_value_red = 0;
int cur_value_red = 0;
int last_value_blue = 0;
int cur_value_blue = 0;
int last_value1 = 0,last_value2 = 0;
int cur_value1 = 0,cur_value2 = 0;
void setup() {
// init lcd
M5.begin();
M5.Power.begin();
pinMode(26, INPUT);
pinMode(36, INPUT);
M5.Lcd.clear(BLACK);
M5.Lcd.setTextColor(YELLOW);
M5.Lcd.setTextSize(2);
M5.Lcd.setCursor(40, 0);
M5.Lcd.println("Dual Button example");
M5.begin(); //Init M5Stack. 初始化M5Stack
M5.Power.begin(); //Init power 初始化电源模块
pinMode(21, INPUT); //set pin mode to input.设置引脚模式为输入模式
pinMode(22, INPUT);
M5.Lcd.setTextColor(YELLOW); //Set the font color to yellow. 设置字体颜色为黄色
M5.Lcd.setTextSize(2); //Setting the Font size. 设置字号大小
M5.Lcd.setCursor(80, 0); //Set the cursor position to (80,0). 将光标位置设置为(80,0)
M5.Lcd.println("Button example");
M5.Lcd.setTextColor(WHITE);
}
void loop() {
cur_value_red = digitalRead(26);
cur_value_blue = digitalRead(36);
M5.Lcd.setCursor(0,25); M5.Lcd.print("Blue Status: ");
M5.Lcd.setCursor(0,45); M5.Lcd.print("Blue Value: ");
M5.Lcd.setCursor(0,65); M5.Lcd.print(" Red Status: ");
M5.Lcd.setCursor(0,85); M5.Lcd.print(" Red Value: ");
if(cur_value_blue != last_value_blue){
M5.Lcd.fillRect(160,25,100,25,BLACK);
M5.Lcd.fillRect(160,45,100,25,BLACK);
if(cur_value_blue==0){
M5.Lcd.setCursor(160,25); M5.Lcd.print("pressed");
M5.Lcd.setCursor(160,45); M5.Lcd.print("0");
Serial.println("Button Status: blue pressed");
Serial.println(" value: 0");
cur_value1 = digitalRead(22); // read the value of BUTTON. 读取22号引脚的值
cur_value2 = digitalRead(21);
M5.Lcd.setCursor(90,25); M5.Lcd.print("Btn.1 Btn.2");
M5.Lcd.setCursor(0,45); M5.Lcd.print("Value: ");
M5.Lcd.setCursor(0,85); M5.Lcd.print("State: ");
if(cur_value1 != last_value1){
M5.Lcd.fillRect(85,45,75,85,BLACK); //Draw a black rectangle 75 by 85 at (85,45). 在(85,45)处绘制宽75,高85的黑色矩形
if(cur_value1==0){
M5.Lcd.setCursor(95,45); M5.Lcd.print("0"); // display the status
M5.Lcd.setCursor(95,85); M5.Lcd.print("pre");
}
else{
M5.Lcd.setCursor(160,25); M5.Lcd.print("released");
M5.Lcd.setCursor(160,45); M5.Lcd.print("1");
Serial.println("Button Status: blue released");
Serial.println(" value: 1");
M5.Lcd.setCursor(95,45); M5.Lcd.print("1"); // display the status
M5.Lcd.setCursor(95,85); M5.Lcd.print("rel");
}
last_value_blue = cur_value_blue;
last_value1 = cur_value1;
}
if(cur_value_red != last_value_red){
M5.Lcd.fillRect(160,65,100,25,BLACK);
M5.Lcd.fillRect(160,85,100,25,BLACK);
if(cur_value_red==0){
M5.Lcd.setCursor(160,65); M5.Lcd.print("pressed");
M5.Lcd.setCursor(160,85); M5.Lcd.print("0");
Serial.println("Button Status: red pressed");
Serial.println(" value: 0");
}
else{
M5.Lcd.setCursor(160,65); M5.Lcd.print("released");
M5.Lcd.setCursor(160,85); M5.Lcd.print("1");
Serial.println("Button Status: red released");
Serial.println(" value: 1");
}
last_value_red = cur_value_red;
if(cur_value2 != last_value2){
M5.Lcd.fillRect(170,45,75,85,BLACK);
if(cur_value2==0){
M5.Lcd.setCursor(185,45); M5.Lcd.print("0"); // display the status
M5.Lcd.setCursor(185,85); M5.Lcd.print("pre");
}
else{
M5.Lcd.setCursor(185,45); M5.Lcd.print("1"); // display the status
M5.Lcd.setCursor(185,85); M5.Lcd.print("rel");
}
last_value2 = cur_value2;
}
M5.update();
}