Skip to content

Commit

Permalink
fix some error
Browse files Browse the repository at this point in the history
  • Loading branch information
Tinyu-Zhao committed Jun 12, 2024
1 parent e56d49a commit ed8abed
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
10 changes: 5 additions & 5 deletions examples/Unit_4RELAY_M5Atom/Unit_4RELAY_M5Atom.ino
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
UNIT_4RELAY relay;

void setup() {
M5.begin(); // Init M5Atom. 初始化 M5Atom
M5.begin(true, false, false); // Init M5Atom. 初始化 M5Atom
Serial.print(relay.begin(&Wire, 26, 32));
relay.Init(1); // Set the lamp and relay to synchronous mode(Async =
// 0,Sync = 1). 将灯和继电器设为同步模式
Expand All @@ -45,10 +45,10 @@ void setup() {
char count_i = 0;

void loop() {
relay.relayAll(1);
delay(1000);
relay.relayAll(0);
delay(1000);
// relay.relayAll(1);
// delay(1000);
// relay.relayAll(0);
// delay(1000);

if (M5.Btn.wasPressed()) { // If button A is pressed. 如果按键A按下
if ((count_i < 4)) { // Control relays turn on/off in sequence.
Expand Down
17 changes: 8 additions & 9 deletions examples/Unit_4RELAY_M5Core2/Unit_4RELAY_M5Core2.ino
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,13 @@ UNIT_4RELAY relay;
void setup() {
M5.begin(true, false, true, true); // Init M5Core2 And the I2C port(21,22).
// 初始化 M5Core2 和I2C(21,22)端口
M5.Lcd.setCursor(
80, 0, 4); // Set the cursor position to (80,0). 将光标位置设置为(80,0)
M5.Lcd.setCursor(80, 0,
4); // Set the cursor position to (80,0). 将光标位置设置为(80,0)
M5.Lcd.print("4-RELAY UNIT\n\n");
M5.Lcd.print(" Relay State: \n Sync Mode: ");
M5.Lcd.setCursor(0, 220, 2);
M5.Lcd.print("Independent switch Sync/Async ALL relay");
relay.begin();
relay.Init(0); // Set the lamp and relay to asynchronous mode(Async =
// 0,Sync = 1). 将灯和继电器设为非同步模式
}
Expand All @@ -50,16 +51,15 @@ char count_i = 0;
bool sync_flag = 0, all_flag = 0;

void loop() {
M5.update(); // Check button down state. 检测按键按下状态
M5.update(); // Check button down state. 检测按键按下状态
if (M5.BtnA.wasPressed()) { // If button A is pressed. 如果按键A按下
M5.Lcd.fillRect(160, 50, 100, 20, BLACK);
M5.Lcd.setCursor(160, 50, 4);
if (count_i < 4) {
M5.Lcd.printf("%d ON", count_i + 1);
if (sync_flag) {
relay.relayWrite(
count_i,
1); // Open the relay at Count_i. 打开count_i处的继电器
relay.relayWrite(count_i,
1); // Open the relay at Count_i. 打开count_i处的继电器
} else
relay.ledWrite(count_i,
1); // Turn on count_I to get led lights.
Expand All @@ -71,9 +71,8 @@ void loop() {
(count_i - 4),
0); // Close the relay at Count_i. 关闭count_i处的继电器
} else
relay.ledWrite(
(count_i - 4),
0); // Turn off the COUNt_I leds. 关闭count_i出得led灯
relay.ledWrite((count_i - 4),
0); // Turn off the COUNt_I leds. 关闭count_i出得led灯
}
count_i++;
if (count_i >= 8) count_i = 0;
Expand Down

0 comments on commit ed8abed

Please sign in to comment.