按键回调函数相关求助-Arduino中文社区 - Powered by Discuz!

Arduino中文社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 373|回复: 1

[未解决] 按键回调函数相关求助

[复制链接]
发表于 2022-6-23 15:36 | 显示全部楼层 |阅读模式
功能:在APP端设置了4个按键,按下每个按键端口输出不同的数组

问题:a,b,c,d四个按键对应输出A,B,C,D四个数组,但实际上按下b会输出AB两个数组的数,按下c会输出ABC三个数组的数,按下d会输出ABCD四个数组的数。求助。。。
代码:
#define BLINKER_WIFI

#include <Blinker.h>
#include <Arduino.h>
char DATA1[]={0x55,0xAA,0x11,0x02,0x01,0x10,0x24,0x02};
char DATA2[]={0x55,0xAA,0x11,0x02,0x01,0x20,0x34,0x32};
char DATA3[]={0x55,0xAA,0x22,0x02,0x01,0x10,0x35,0x31};
char DATA4[]={0x55,0xAA,0x22,0x02,0x01,0x20,0x45,0x01};
char auth[] = "5b05dc85109b";//Your Device Secret Key
char ssid[] = "keke";//Your WiFi network SSID or name
char pswd[] = "123456789";//Your WiFi network WPA password or WEP key
BlinkerButton Button1("btn-1l");
BlinkerButton Button2("btn-1r");
BlinkerButton Button3("btn-2l");
BlinkerButton Button4("btn-2r");
void Button1_callback(const String & state)
{
   digitalWrite(5,HIGH);
   Serial.print(DATA1);
   Blinker.delay(300);
}
void Button2_callback(const String & state)
{
   digitalWrite(5,HIGH);
   Serial.print(DATA2);
   Blinker.delay(300);
}
void Button3_callback(const String & state)
{
   digitalWrite(5,HIGH);
   Serial.print(DATA3);
   Blinker.delay(300);
}
void Button4_callback(const String & state)
{
   digitalWrite(5,HIGH);
   Serial.print(DATA4);
   Blinker.delay(300);
}
void setup() {
  Serial.begin(14400);
  pinMode(5,OUTPUT);
  Blinker.begin(auth, ssid, pswd);
  Button1.attach(Button1_callback);
  Button2.attach(Button2_callback);
  Button3.attach(Button3_callback);
  Button4.attach(Button4_callback);
}

void loop() {
  Blinker.run();
  digitalWrite(5,LOW);
}

 楼主| 发表于 2022-6-23 15:39 | 显示全部楼层
顶顶顶,求助
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|Archiver|手机版|Arduino中文社区

GMT+8, 2024-12-3 03:00 , Processed in 0.070039 second(s), 16 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表