查看: 367|回复: 1

blinker中的button-wifi例程

[复制链接]
  • TA的每日心情
    开心
    2019-5-7 20:44
  • 签到天数: 1 天

    [LV.1]初来乍到

    发表于 2019-5-12 23:52 | 显示全部楼层 |阅读模式
    blinker中的button-wifi例程控制小车,每次程序打开app进入控制页面,按钮按住(press状态)然后松开(pressup状态)松开不起作用,任意点击一个按钮才会出现松开状态(pressup)。后面再按住,松开就正常了,请问问题出在哪里?

    kittenblock中小学创客名师推荐的图形化编程软件

    /* *****************************************************************
     *
     * 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);
      
    }

  • TA的每日心情
    郁闷
    2018-12-6 22:21
  • 签到天数: 48 天

    [LV.5]常住居民I

    发表于 2019-5-13 00:49 | 显示全部楼层
    我这边测试是正常的,请在android 8.0或者9.0的手机上测试最新版本,如果还是有问题,请按提问要求发帖:
    https://www.arduino.cn/thread-83658-1-1.html
    如果以上内容对你有帮助,你可以通过打赏支持作者
    您需要登录后才可以回帖 登录 | 立即注册  

    本版积分规则

    热门推荐

    Arduino lcd屏幕亮了但是不显示字符
    Arduino lcd屏幕亮了但是
    Arduino的lcd屏亮了但是上面没有字符显示,串进去的滑动变阻器也旋过了,但是还是没有
    【原创】全球最小口袋3D打印机mini one直播教程贴
    【原创】全球最小口袋3D打
    最近闲得蛋疼,没事搞个掌上3D打印机,先放效果图吧。 搞了半天,终于能正常打印,
    [限时福利]5分钟带你快速了解新一代开发板:M5STACK
    [限时福利]5分钟带你快速
    一、什么是M5Stack M5Stack是一种模块化、可堆叠扩展的开发板,每个模块
    【Arduino】108种传感器模块系列实验(98)---L298N电机驱动板
    【Arduino】108种传感器模
    37款传感器与模块的提法,在网络上广泛流传,其实Arduino能够兼容的传感器模块肯定是
    两个ESP8266通过云端实现远程数据交互
    两个ESP8266通过云端实现
    原理简述:利用发布订阅模式。一个ESP8266作为消息发布者,另一个ESP8266作为消息订阅
    Copyright   ©2015-2016  Arduino中文社区  Powered by©Discuz!   ( 蜀ICP备14017632号-3 )
    快速回复 返回顶部 返回列表