当前位置:   article > 正文

blinker小白入门学习_esp32_#include

#include

持续更新

应用:远程控制esp32的io。

先看官方给的示例点灯科技 (diandeng.tech)

  1. #define BLINKER_WIFI
  2. #include <Blinker.h>
  3. char auth[] = "Your Device Secret Key";
  4. char ssid[] = "Your WiFi network SSID or name";
  5. char pswd[] = "Your WiFi network WPA password or WEP key";
  6. // 新建组件对象
  7. BlinkerButton Button1("btn-abc");
  8. BlinkerNumber Number1("num-abc");
  9. int counter = 0;
  10. // 按下按键即会执行该函数
  11. void button1_callback(const String & state) {
  12. BLINKER_LOG("get button state: ", state);
  13. digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
  14. }
  15. // 如果未绑定的组件被触发,则会执行其中内容
  16. void dataRead(const String & data)
  17. {
  18. BLINKER_LOG("Blinker readString: ", data);
  19. counter++;
  20. Number1.print(counter);
  21. }
  22. void setup() {
  23. // 初始化串口
  24. Serial.begin(115200);
  25. BLINKER_DEBUG.stream(Serial);
  26. // 初始化有LED的IO
  27. pinMode(LED_BUILTIN, OUTPUT);
  28. digitalWrite(LED_BUILTIN, HIGH);
  29. // 初始化blinker
  30. Blinker.begin(auth, ssid, pswd);
  31. Blinker.attachData(dataRead);
  32. Button1.attach(button1_callback);
  33. }
  34. void loop() {
  35. Blinker.run();
  36. }

上面的代码中有很多的函数,我提取了一部分写下了能直接控制io的代码。

  1. #define BLINKER_WIFI
  2. #include <Blinker.h>
  3. char auth[] = "安全码";
  4. char ssid[] = "wifi名";
  5. char pswd[] = "wifi密码";
  6. BlinkerButton Button1("btn-test"); //在blinkerapp上创建一个按钮组件,名称需要相同
  7. int ledPin = 4;//我的esp32的io4是板载led
  8. //当app上的按钮组件被按下时执行
  9. void button1_callback(const String & state){
  10. BLINKER_LOG("BLINKER_LOG: ", !digitalRead(ledPin));//日志,在编译器串口上显示。
  11. digitalWrite(ledPin, !digitalRead(ledPin));//简易写法,把每次读取的led状态写反,实现简单开关功能
  12. if(digitalRead(ledPin)==HIGH){
  13. BLINKER_LOG("BLINKER_LOG: ", "开灯");
  14. }else if(digitalRead(ledPin)==LOW){
  15. BLINKER_LOG("BLINKER_LOG: ", "关灯");
  16. }
  17. }
  18. void setup() {
  19. // put your setup code here, to run once:
  20. BLINKER_DEBUG.stream(Serial);
  21. Serial.begin(115200);
  22. pinMode(ledPin, OUTPUT);
  23. digitalWrite(ledPin, LOW);
  24. Blinker.begin(auth, ssid, pswd);
  25. Button1.attach(button1_callback);
  26. }
  27. void loop() {
  28. // put your main code here, to run repeatedly:
  29. Blinker.run();
  30. }

下面的是实现滑块的数值显示在num上,正在完成中。。

  1. #define BLINKER_WIFI
  2. #define LED 4
  3. #include <Blinker.h>
  4. #define BUTTON1 "control"
  5. #define BUTTON2 "settime"
  6. #define NUMBER1 "clockdown"
  7. #define NUMBER2 "timecount"
  8. #define SLIDER1 "timemin"
  9. BlinkerButton Button1(BUTTON1);
  10. BlinkerNumber Number1(NUMBER1);
  11. BlinkerSlider Slider1(SLIDER1);
  12. void Number1_callback(const String & data)
  13. {
  14. }
  15. void Button1_callback(const String & state)
  16. {
  17. }
  18. void slider1_callback(int32_t value)
  19. {
  20. BLINKER_LOG("get slider value: ", value);
  21. }
  22. void dataRead(const String & data)
  23. {
  24. BLINKER_LOG("Blinker readString: ", data);
  25. Blinker.vibrate();
  26. uint32_t BlinkerTime = millis();
  27. Blinker.print("millis", BlinkerTime);
  28. Number1.icon("icon_1");
  29. Number1.color("#FFFFFF");
  30. Number1.unit("ms");
  31. Number1.print(Button1_callback.value);
  32. //Slider1.color("#FFFFFF");
  33. //Slider1.print(random(0, 128));
  34. }
  35. //af1d7be5879a
  36. //TSLMTH2.4G
  37. //lff870311
  38. char auth[] = "af1d7be5879a";
  39. char ssid[] = "TSLMTH2.4G";
  40. char pswd[] = "lff870311";
  41. void setup() {
  42. // put your setup code here, to run once:
  43. Serial.begin(115200);
  44. BLINKER_DEBUG.stream(Serial);
  45. Blinker.begin(auth, ssid, pswd);
  46. Slider1.attach(slider1_callback);
  47. Blinker.attachData(dataRead);
  48. }
  49. void loop() {
  50. // put your main code here, to run repeatedly:
  51. Blinker.run();
  52. }
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小小林熬夜学编程/article/detail/514075
推荐阅读
相关标签
  

闽ICP备14008679号