# blinker-library
Blinker library for embedded hardware. Works with Arduino, ESP8266, ESP32.
# What's Blinker
[Blinker](https://blinker.app/) is a platform with iOS and Android apps to control embedded hardware like Arduino. You can easily build graphic interfaces for all your projects by simply dragging and dropping widgets.
[Blinker](https://blinker.app/) 是一个运行在 IOS 和 Android 上用于控制嵌入式硬件的应用程序。你可以通过拖放控制组件,轻松地为你的项目建立图形化控制界面。
# Reference/参考
* [EN-英文](https://github.com/blinker-iot/blinker-doc/wiki/Blinker-Arduino-library-reference)
* [CN-中文](https://github.com/blinker-iot/blinker-doc/wiki/Blinker-Arduino-%E5%BA%93%E4%BD%BF%E7%94%A8%E6%89%8B%E5%86%8C)
* [CN-中文/官网](https://doc.blinker.app/?file=003-%E7%A1%AC%E4%BB%B6%E5%BC%80%E5%8F%91/02-Arduino%E6%94%AF%E6%8C%81)
<!--
---
# 目前支持的硬件
* Arduino boards
- Arduino Uno, Duemilanove
- Arduino Nano, Mini, Pro Mini, Pro Micro, Due, Mega
* 使用 [esp8266/arduino](https://github.com/esp8266/arduino) 的ESP8266
* 使用 [espressif/arduino-esp32](https://github.com/espressif/arduino-esp32) 的ESP32
# 连接类型
* Bluetooth Smart (BLE 4.0)
* WiFi
* MQTT
# 准备工作
开始使用前你需要做好如下准备:
* [Arduino IDE](https://www.arduino.cc/en/Main/Software) 1.6.12及更新版本
* 使用 Arduino IDE 的开发板管理器安装 [esp8266/arduino](https://github.com/esp8266/arduino)
* 按照 [安装说明](https://github.com/espressif/arduino-esp32#installation-instructions) 安装 [espressif/arduino-esp32](https://github.com/espressif/arduino-esp32)
# Blinker接口函数
## 设备配置
### Blinker.begin()
使用 **Blinker.begin()** 来配置 Blinker:
```
Blinker.begin(...);
```
根据你使用的连接方式选择不同的参数用于配置Blinker
BLE:
```
#define BLINKER_BLE
#include <Blinker.h>
void setup() {
Blinker.begin();
}
```
>串口蓝牙模块:
>**Blinker.begin()** 将使用默认设置配置 Serial(默认使用软串口)
>
>Blinker.begin();// 默认设置: 数字IO 2(RX) 3(TX), 波特率 9600 bps
>Blinker.begin(4, 5);// 设置数字IO 4(RX) 5(TX), 默认波特率 9600 bps
>Blinker.begin(4, 5, 115200);// 设置数字IO 4(RX) 5(TX) 及波特率 115200 bps
>
>若配置时Blinker.begin(0, 1);
>0 1对应硬串口的RX TX, 库会默认使用硬串口与BLE模块进行通信
>Blinker.begin(15, 14);//Arduino MEGA中如15, 14对应硬串口Serial3
>
>注意使用软串口时:
>使用Arduino MEGA时以下IO可以设置为RX: 10, 11, 12, 13, 50, 51, 52, 53, 62, 63, 64, 65, 66, 67, 68, 69
>使用Arduino Leonardo时以下IO可以设置为RX: 8, 9, 10, 11, 14, 15, 16
WiFi:
```
#define BLINKER_WIFI
#include <Blinker.h>
void setup() {
Blinker.begin(ssid, pswd);
}
```
MQTT:
```
#define BLINKER_MQTT
#include <Blinker.h>
void setup() {
Blinker.begin(auth, ssid, pswd);
}
```
> MQTT 支持的硬件: WiFiduino, WiFiduino32, ESP8266, ESP32
**begin()** 主要完成以下配置:
1.初始化硬件设置;
2.连接网络并广播设备信息等待app连接;
## 连接管理
### Blinker.connect()
建立 **Blinker** 设备间连接并返回连接状态, 默认超时时间为10秒
```
bool result = Blinker.connect();
uint32_t timeout = 30000;//ms
bool result = Blinker.connect(timeout);
```
### Blinker.disconnect()
断开 **Blinker** 设备间连接
```
Blinker.disconnect();
```
### Blinker.connected()
返回 **Blinker** 设备间连接状态
```
bool result = Blinker.connected();
```
### Blinker.run()
此函数需要频繁调用以保持设备间连接及处理收到的数据, 建议放在 **loop()** 函数中
```
void loop() {
Blinker.run();
}
```
## 数据管理
### Blinker.available()
检测是否有接收到数据
```
bool result = Blinker.available();
```
### Blinker.readString()
读取接收到的数据
```
String data = Blinker.readString();
```
`*读取数据最大为 256 字节`
### Blinker.print()
发送数据
```
Blinker.print(data);
```
发送一个Json数据, 如 {text1:data}
```
Blinker.print(text1, data);
```
发送一个带单位的Json数据, eg: {"temp":"30.2 °C"}
```
Blinker.print("temp", 30.2, "°C");
```
>发送的Json数据可以在 Blinker APP 的 TEXT 组件中显示
```
*发送数据最大为 128 字节
*MQTT方式接入时, print需间隔1s以上
例:
Blinker.print("hello");
Blinker.delay(1000);
Blinker.print("world);
```
### Blinker.beginFormat() && Blinker.endFormat()
当使用 **beginFormat** 时, **print** 发送出的数据都将以 Json 格式存入发送数据中。 这个发送数据将在使用 **endFormat** 时发送出去。
```
Blinker.beginFormat();
Blinker.print("Hello","Blinker");
Blinker.print("start","end");
Blinker.print("number",123);
Blinker.endFormat();
```
>使用 endFormat 后, 发送的 Json 数据: {"Hello":"Blinker","start":"end","number":123}
### Blinker.notify()
使用 **notify** 时, 发送数据以感叹号开始, 将会发送消息通知到app, 否则将会发送Json数据到app
发送通知
```
Blinker.notify("!notify");
```
发送Json数据, 如 {"notice":"notify"}
```
Blinker.notify("notify");
```
## App Widgets
### Blinker.wInit()
组件初始化, 建议在使用前初始化 **Button** 、**Slider** 、 **Toggle** 及 **RGB**
```
Blinker.wInit("ButtonName", W_BUTTON);
Blinker.wInit("SliderName", W_SLIDER);
Blinker.wInit("ToggleName", W_TOGGLE);
Blinker.wInit("RGBName", W_RGB);//键词, 类型
```
>类型:
>W_BUTTON 按键
>W_SLIDER 滑动条
>W_TOGGLE 开关
>W_RGB RGB调色板
>以上四种组件数量限制为 16个/种
### Blinker.button()
读取开关/按键数据, 按下(Pressed)时返回true, 松开(Released)时返回false
```
bool result = Blinker.button("Button1");
```
### Blinker.slider()
读取滑动条数据
```
uint8_t result = Blinker.slider("Slider1");
```
### Blinker.toggle()
读取拨动开关数据, 打开(ON)时返回true, 关闭(OFF)时返回false
```
bool result = Blinker.toggle("Toggle1");
```
### Blinker.joystick()
读取摇杆数据
```
uint8_t result_X = Blinker.joystick(J_Xaxis);
uint8_t result_Y = Blinker.joystick(J_Yaxis);
```
### BlinkerButton
按键组件在App中可以设置 按键/开关/自定义 三种模式,
**按键** 模式下支持 点按/长按/释放(tap/pre/pup) 三个动作
**开关** 模式下支持 打开/关闭(on/off) 两个动作
**自定义** 模式下支持 自定义指令 发送
初始化, 创建对象
```
#define BUTTON_1 "ButtonKey"
BlinkerButton Button1(BUTTON_1);
```
用于处理 **button** 收到数据的回调函数
```
void button1_callback(const String & state)
{
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
BLINKER_LOG2("get button state: ", state);
}
```
> 在回调函数中, **state** 的值为:
> **按键** : 点按(tap)/长按(pre)/释放(pup)
> **开关** : 打开(on)/关闭(off)
> **自定义** : 你设置的值
在 **setup()** 中注册回调函数
```
Button1.attach(button1_callback);
```
> 也可以在初始化时注册回调函数:
> BlinkerButton Button1(BUTTON_1, button1_callback);
#### Button1.icon();
Button1.color("#FFFFFF");
Button1.text("Your button name or describe");
Button1.print("on");
### BlinkerJoystick
### BlinkerRGB
### BlinkerSlider
### BlinkerNumber
### BlinkerText
### BUILTIN_SWITCH
### Blinker.ahrs()
开启手机 **AHRS** 功能
```
Blinker.attachAhrs();
```
读取 **AHRS** 数据
```
int16_t result_Yaw = Blinker.ahrs(Yaw);
int16_t result_Roll = Blinker.ahrs(Roll);
int16_t result_Pitch = Blinker.ahrs(Pitch);
```
关闭手机 **AHRS** 功能
```
Blinker.dettachAhrs();
```
### Blinker.gps()
刷新手机 **GPS** 功能
```
Blinker.freshAhrs();
```
读取 **GPS** 数据
```
String result_LONG = Blinker.gps(LONG);
String result_LAT = Blinker.gps(LAT);
```
> LONG 经度
> LAT 维度
<!-- ### Blinke
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
嵌入式优质项目,资源经过严格测试可直接运行成功且功能正常的情况才上传,可轻松copy复刻,拿到资料包后可轻松复现出一样的项目。 本人单片机开发经验充足,深耕嵌入式领域,有任何使用问题欢迎随时与我联系,我会及时为你解惑,提供帮助。 【资源内容】:包含完整源码+工程文件+说明,项目具体内容可查看下方的资源详情。 【附带帮助】: 若还需要嵌入式物联网单片机相关领域开发工具、学习资料等,我会提供帮助,提供资料,鼓励学习进步。 【本人专注嵌入式领域】: 有任何使用问题欢迎随时与我联系,我会及时解答,第一时间为你提供帮助,CSDN博客端可私信,为你解惑,欢迎交流。 【建议小白】: 在所有嵌入式开发中硬件部分若不会画PCB/电路,可选择根据引脚定义将其代替为面包板+杜邦线+外设模块的方式,只需轻松简单连线,下载源码烧录进去便可轻松复刻出一样的项目 【适合场景】: 相关项目设计中,皆可应用在项目开发、毕业设计、课程设计、期末/期中/大作业、工程实训、大创等学科竞赛比赛、初期项目立项、学习/练手等方面中 可借鉴此优质项目实现复刻,也可以基于此项目进行扩展来开发出更多功能
资源推荐
资源详情
资源评论
收起资源包目录
Arduino的各种优质项目集合-包括灯泡控制等.zip(毕设/课设/竞赛/实训/项目开发) (521个子文件)
AUTHORS 166B
libsha1.c 7KB
cencode.c 3KB
cdecode.c 3KB
tcpip.cpp 33KB
tcpip.cpp 33KB
OneWireHub.cpp 31KB
main.cpp 30KB
WebSocketsServer.cpp 26KB
Adafruit_MQTT.cpp 25KB
enc28j60.cpp 23KB
enc28j60.cpp 23KB
WebSocketsClient.cpp 23KB
WebSockets.cpp 19KB
OneWire.cpp 18KB
irPronto.cpp 15KB
dhcp.cpp 14KB
dhcp.cpp 14KB
DS2506.cpp 13KB
DS2431.cpp 9KB
Adafruit_ESP8266.cpp 9KB
Keypad.cpp 9KB
DHT.cpp 8KB
stash.cpp 8KB
stash.cpp 8KB
IRremote.cpp 8KB
DS2502.cpp 7KB
DS2423.cpp 7KB
MsTimer2.cpp 7KB
irRecv.cpp 6KB
ir_RC5_RC6.cpp 6KB
ir_Template.cpp 6KB
webutil.cpp 5KB
webutil.cpp 5KB
DS2433.cpp 5KB
DS2408.cpp 5KB
DS2450.cpp 5KB
DS2438.cpp 5KB
irSend.cpp 4KB
OneWireItem.cpp 4KB
Adafruit_MQTT_Client.cpp 4KB
DS18B20.cpp 4KB
dns.cpp 4KB
dns.cpp 4KB
ir_Aiwa.cpp 3KB
DHT.cpp 3KB
BAE910.cpp 3KB
ir_Denon.cpp 3KB
ir_Mitsubishi.cpp 3KB
sam.cpp 3KB
ir_JVC.cpp 3KB
ir_Whynter.cpp 3KB
ir_Samsung.cpp 3KB
ir_NEC.cpp 3KB
ir_Sony.cpp 3KB
ir_Panasonic.cpp 3KB
ir_Sanyo.cpp 3KB
DS2890.cpp 3KB
ir_LG.cpp 2KB
ir_Sharp.cpp 2KB
EtherCard.cpp 2KB
EtherCard.cpp 2KB
udpserver.cpp 2KB
udpserver.cpp 2KB
bufferfiller.cpp 2KB
bufferfiller.cpp 2KB
ir_Dish.cpp 2KB
Key.cpp 1KB
ir_Lego_PF.cpp 1KB
DS2413.cpp 1KB
Ultrasonic.cpp 1KB
esp32.cpp 1KB
DS2405.cpp 624B
DS2401.cpp 366B
platform.cpp 280B
Doxymods.css 1KB
Doxymods.css 1KB
Doxyfile 104KB
Doxyfile 104KB
.gitattributes 66B
.gitignore 61B
.gitignore 53B
BlinkerApi.h 209KB
BlinkerProtocol.h 52KB
BlinkerAuto.h 46KB
BlinkerMQTT.h 37KB
BlinkerPRO.h 33KB
boarddefs.h 20KB
BlinkerConfig.h 20KB
EtherCard.h 20KB
EtherCard.h 20KB
BlinkerEvent.h 16KB
platform.h 16KB
BlinkerWlan.h 16KB
OneWire_direct_gpio.h 14KB
IRremote.h 12KB
Adafruit_MQTT.h 11KB
BlinkerOTA.h 9KB
enc28j60.h 9KB
enc28j60.h 9KB
共 521 条
- 1
- 2
- 3
- 4
- 5
- 6
资源评论
阿齐Archie
- 粉丝: 1w+
- 资源: 2303
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功