ProtocolZig.readBytes()
ProtocolZig.readBytes(uint8_t *_cmd, uint8_t *_data, uint8_t _len)
描述 读取数据,将读取到的长度为_len的数据放到数组_data[]中,将指令数据赋给_cmd
参数
返回值 函数无返回值
示例 /*
[head,2byte,0xAA 0xBB] [type,1byte,TYPE_NUM] [data,16byte]
Example:
AA BB C8 DC 05 DC 05 D0 07 EF 03 DC 05 DC 05 DC 05 DC 05
*/
#include <Microduino_Protocol.h>
#define NRF_CHANNEL 70 //nRF通道
/* 预先设置好两个通讯地址,总长度为6位 */
uint8_t addresses[][6] = {"1Node","2Node"};
RF24 radio(D9, D10);
ProtocolnRF nrfProtocol(&radio, 16); //采用ProtocolnRF,数据长度为16个字节
uint8_t recData[16];
uint8_t recCmd;
void setup() {
Serial.begin(9600);
//设置nRF通道, 本机地址,目标地址
if (nrfProtocol.begin(NRF_CHANNEL, addresses[0], addresses[1])) {
Serial.println("nrf24 module Initialization ");
}
else{
Serial.println("nrf24 module is not founded ");
}
}
void loop() {
if(nrfProtocol.available())
{
nrfProtocol.readWords(&recCmd, recData, 16);
Serial.println("protocol Received !");
Serial.print("recCmd: ");
Serial.print(recCmd);
Serial.print(" Data:");
for(uint8_t i=0; i<16; i++)
{
Serial.print(" ");
Serial.print(recData[i]);
}
Serial.println();
}
}
其他 |