blinker中的button-wifi例程-Arduino中文社区 - Powered by Discuz!

Arduino中文社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 2982|回复: 1

blinker中的button-wifi例程

[复制链接]
发表于 2019-5-12 23:52 | 显示全部楼层 |阅读模式
blinker中的button-wifi例程控制小车,每次程序打开app进入控制页面,按钮按住(press状态)然后松开(pressup状态)松开不起作用,任意点击一个按钮才会出现松开状态(pressup)。后面再按住,松开就正常了,请问问题出在哪里?
[mw_shl_code=arduino,true]/* *****************************************************************
*
* Download latest Blinker library here:
* https://github.com/blinker-iot/blinker-library/archive/master.zip
*
*
* Blinker is a cross-hardware, cross-platform solution for the IoT.
* It provides APP, device and server support,
* and uses public cloud services for data transmission and storage.
* It can be used in smart home, data monitoring and other fields
* to help users build Internet of Things projects better and faster.
*
* Make sure installed 2.5.0 or later ESP8266/Arduino package,
* if use ESP8266 with Blinker.
* https://github.com/esp8266/Arduino/releases
*
* Docs: https://doc.blinker.app/
*       https://github.com/blinker-iot/blinker-doc/wiki
*
* *****************************************************************
*
* Blinker 库下载地址:
* https://github.com/blinker-iot/blinker-library/archive/master.zip
*
* Blinker 是一套跨硬件、跨平台的物联网解决方案,提供APP端、设备端、
* 服务器端支持,使用公有云服务进行数据传输存储。可用于智能家居、
* 数据监测等领域,可以帮助用户更好更快地搭建物联网项目。
*
* 如果使用 ESP8266 接入 Blinker,
* 请确保安装了 2.5.0 或更新的 ESP8266/Arduino 支持包。
* https://github.com/esp8266/Arduino/releases
*
* 文档: https://doc.blinker.app/
*       https://github.com/blinker-iot/blinker-doc/wiki
*
* *****************************************************************/

#define BLINKER_WIFI

#include <Blinker.h>

char auth[] = "97971d25a1b0";
char ssid[] = "ketingkz";
char pswd[] = "jurenpass1207";

#define BUTTON_1 "btn-abc"
#define BUTTON_2 "btn-s"
#define BUTTON_3 "btn-x"
#define BUTTON_4 "btn-z"
#define BUTTON_5 "btn-y"
#define BUTTON_6 "btn-t"
int motorL1 = D0; //左边轮子
int motorL2 = D1;
int motorR1 = D7; //右边轮子
int motorR2 = D8;
BlinkerButton Button1(BUTTON_1);
BlinkerButton Button2(BUTTON_2);
BlinkerButton Button3(BUTTON_3);
BlinkerButton Button4(BUTTON_4);
BlinkerButton Button5(BUTTON_5);
BlinkerButton Button6(BUTTON_6);

void button1_callback(const String & state)
{
    digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
    BLINKER_LOG("get button state: ", state);

    if (state == BLINKER_CMD_BUTTON_TAP) {
        BLINKER_LOG("Button tap!");

        Button1.icon("icon_1");
        Button1.color("#FFFFFF");
        Button1.text("Your button name or describe");
        Button1.print();
    }
    else if (state == BLINKER_CMD_BUTTON_PRESSED) {
        BLINKER_LOG("Button pressed!");

        Button1.icon("icon_1");
        Button1.color("#FFFFFF");
        Button1.text("Your button name or describe");
        Button1.print();
    }
    else if (state == BLINKER_CMD_BUTTON_RELEASED) {
        BLINKER_LOG("Button released!");

        Button1.icon("icon_1");
        Button1.color("#FFFFFF");
        Button1.text("Your button name or describe");
        // Button1.text("Your button name", "describe");
        Button1.print();
    }
   
    else {
        BLINKER_LOG("Get user setting: ", state);

        Button1.icon("icon_1");
        Button1.color("#FFFFFF");
        Button1.text("Your button name or describe");
        // Button1.text("Your button name", "describe");
        Button1.print();
    }
}

void button2_callback(const String & state)
{
   // digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
    BLINKER_LOG("get button state: ", state);

    if (state == BLINKER_CMD_BUTTON_TAP) {
        BLINKER_LOG("Button tap!");
     
        Button2.icon("icon_1");
        Button2.color("#FFFFFF");
        Button2.text("前进");
       Button2.print();
        line();  
        delay(200);
        lull();
    }
    else if (state == BLINKER_CMD_BUTTON_PRESSED) {
        BLINKER_LOG("Button pressed!");

        Button2.icon("icon_1");
        Button2.color("#FFFFFF");
        Button2.text("连续前进");
        Button2.print();
        line();  
        delay(200);
    }
    else if (state == BLINKER_CMD_BUTTON_RELEASED) {
        BLINKER_LOG("Button released!");

        Button2.icon("icon_1");
        Button2.color("#FFFFFF");
        Button2.text("停止前进");
        // Button2.text("Your button name", "describe");
        Button2.print();
        lull();
    }
   
    else {
        BLINKER_LOG("Get user setting: ", state);

        Button2.icon("icon_1");
        Button2.color("#FFFFFF");
        Button2.text("s");
        // Button2.text("Your button name", "describe");
        Button2.print();
    }
}
void button3_callback(const String & state)
{
   // digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
    BLINKER_LOG("get button state: ", state);

    if (state == BLINKER_CMD_BUTTON_TAP) {
        BLINKER_LOG("Button tap!");

        Button3.icon("icon_1");
        Button3.color("#FFFFFF");
        Button3.text("后退");
        Button3.print();
        back();
        delay(200);
        lull();
    }
    else if (state == BLINKER_CMD_BUTTON_PRESSED) {
        BLINKER_LOG("Button pressed!");

        Button3.icon("icon_1");
        Button3.color("#FFFFFF");
        Button3.text("连续后退");
        Button3.print();
        back();
    }
    else if (state == BLINKER_CMD_BUTTON_RELEASED) {
        BLINKER_LOG("Button released!");

        Button3.icon("icon_1");
        Button3.color("#FFFFFF");
        Button3.text("停止后退");
        // Button3.text("Your button name", "describe");
        Button3.print();
        lull();
    }
   
    else {
        BLINKER_LOG("Get user setting: ", state);

        Button3.icon("icon_1");
        Button3.color("#FFFFFF");
        Button3.text("x");
        // Button3.text("Your button name", "describe");
        Button3.print();
    }
}
void button4_callback(const String & state)
{
   // digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
    BLINKER_LOG("get button state: ", state);

    if (state == BLINKER_CMD_BUTTON_TAP) {
        BLINKER_LOG("Button tap!");

        Button4.icon("icon_1");
        Button4.color("#FFFFFF");
        Button4.text("左转");
        Button4.print();
        L();
        delay(200);
        lull();
    }
    else if (state == BLINKER_CMD_BUTTON_PRESSED) {
        BLINKER_LOG("Button pressed!");

        Button4.icon("icon_1");
        Button4.color("#FFFFFF");
        Button4.text("连续左转");
        Button4.print();
        L();
    }
    else if (state == BLINKER_CMD_BUTTON_RELEASED) {
        BLINKER_LOG("Button released!");

        Button4.icon("icon_1");
        Button4.color("#FFFFFF");
        Button4.text("左转停止");
        // Button4.text("Your button name", "describe");
        Button4.print();
        lull();
    }
   
    else {
        BLINKER_LOG("Get user setting: ", state);

        Button4.icon("icon_1");
        Button4.color("#FFFFFF");
        Button4.text("Your button name or describe");
        // Button4.text("Your button name", "describe");
        Button4.print();
    }
}
void button5_callback(const String & state)
{
   // digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
    BLINKER_LOG("get button state: ", state);

    if (state == BLINKER_CMD_BUTTON_TAP) {
        BLINKER_LOG("Button tap!");

        Button5.icon("icon_1");
        Button5.color("#FFFFFF");
        Button5.text("右转");
        Button5.print();
        R();
        delay(200);
        lull();
    }
    else if (state == BLINKER_CMD_BUTTON_PRESSED) {
        BLINKER_LOG("Button pressed!");

        Button5.icon("icon_1");
        Button5.color("#FFFFFF");
        Button5.text("连续右转");
        Button5.print();
        R();
    }
    else if (state == BLINKER_CMD_BUTTON_RELEASED) {
        BLINKER_LOG("Button released!");

        Button5.icon("icon_1");
        Button5.color("#FFFFFF");
        Button5.text("停止右转");
        // Button5.text("Your button name", "describe");
        Button5.print();
        lull();
    }
   
    else {
        BLINKER_LOG("Get user setting: ", state);

        Button5.icon("icon_1");
        Button5.color("#FFFFFF");
        Button5.text("Your button name or describe");
        // Button5.text("Your button name", "describe");
        Button5.print();
    }
}
void button6_callback(const String & state)
{
   // digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
    BLINKER_LOG("get button state: ", state);

    if (state == BLINKER_CMD_BUTTON_TAP) {
        BLINKER_LOG("Button tap!");

        Button6.icon("icon_1");
        Button6.color("#FFFFFF");
        Button6.text("Your button name or describe");
        Button6.print();
        lull();
    }
    else if (state == BLINKER_CMD_BUTTON_PRESSED) {
        BLINKER_LOG("Button pressed!");

        Button6.icon("icon_1");
        Button6.color("#FFFFFF");
        Button6.text("Your button name or describe");
        Button6.print();
         lull();
    }
    else if (state == BLINKER_CMD_BUTTON_RELEASED) {
        BLINKER_LOG("Button released!");

        Button6.icon("icon_1");
        Button6.color("#FFFFFF");
        Button6.text("Your button name or describe");
        // Button6.text("Your button name", "describe");
        Button6.print();
         lull();
    }
   
    else {
        BLINKER_LOG("Get user setting: ", state);

        Button6.icon("icon_1");
        Button6.color("#FFFFFF");
        Button6.text("Your button name or describe");
        // Button6.text("Your button name", "describe");
        Button6.print();
    }
}
void dataRead(const String & data)
{
    BLINKER_LOG("Blinker readString: ", data);

    Blinker.vibrate();
   
    uint32_t BlinkerTime = millis();
    Blinker.print(BlinkerTime);
    Blinker.print("millis", BlinkerTime);
}

void setup()
{
    Serial.begin(115200);
    BLINKER_DEBUG.stream(Serial);

    pinMode(LED_BUILTIN, OUTPUT);
    digitalWrite(LED_BUILTIN, LOW);
     pinMode(motorL1, OUTPUT);
  pinMode(motorL2, OUTPUT);
  pinMode(motorR1, OUTPUT);
  pinMode(motorR2, OUTPUT);

    Blinker.begin(auth, ssid, pswd);
    Blinker.attachData(dataRead);
    Button1.attach(button1_callback);
    Button2.attach(button2_callback);
    Button3.attach(button3_callback);
    Button4.attach(button4_callback);
    Button5.attach(button5_callback);
    Button6.attach(button6_callback);
}

void loop()
{
    Blinker.run();
}
void line() {
   
/* digitalWrite(motorL1, HIGH);
  digitalWrite(motorL2, LOW);
  digitalWrite(motorR1, LOW);
  digitalWrite(motorR2, HIGH);*/
analogWrite(motorL1, 700);
  digitalWrite(motorL2, LOW);
  digitalWrite(motorR1, LOW);
  analogWrite(motorR2, 700);
}

void L() {
  
  digitalWrite(motorL1, LOW);
  analogWrite(motorL2, 700);
  digitalWrite(motorR1, LOW);
  analogWrite(motorR2, 700);


}
void R() {
   
  analogWrite(motorL1, 700);
  digitalWrite(motorL2, LOW);
  analogWrite(motorR1, 700);
  digitalWrite(motorR2, LOW);

}


void back() { //后退函数
   
  digitalWrite(motorL1, LOW);
  analogWrite(motorL2, 700);
  analogWrite(motorR1, 700);
  digitalWrite(motorR2, LOW);
  
}

void lull() {
  digitalWrite(motorL1, HIGH);
  digitalWrite(motorL2, HIGH);
  digitalWrite(motorR1, HIGH);
  digitalWrite(motorR2, HIGH);
  
}[/mw_shl_code]
发表于 2019-5-13 00:49 | 显示全部楼层
我这边测试是正常的,请在android 8.0或者9.0的手机上测试最新版本,如果还是有问题,请按提问要求发帖:
https://www.arduino.cn/thread-83658-1-1.html
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

GMT+8, 2024-11-28 20:56 , Processed in 0.071273 second(s), 15 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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