用户工具

站点工具


reference:library:firmata

Firmata Library

通过Firmata程序库执行Firmata协议,在主机电脑上可与软件进行沟通。当您正在使用时,这允许您可以编写自定义固件而无需创建你自己的协议和对象的编程环境。

方法


begin()

执行程序库

begin(long)

执行程序并覆盖原有默认的传输速率

printVersion()

发送协议版本到主机电脑

blinkVersion()

在pin 13闪现协议版本

printFirmwareVersion()

发送软件名称和版本至主机电脑

setFirmwareVersion(byte major, byte minor)

通过使用缩略图的文件名称和减去.pde来设置软件名称及版本

发送消息

sendAnalog(byte pin, int value)

发送一个模拟消息

sendDigitalPorts(byte pin, byte firstPort, byte secondPort)

发送数字端口作为单独字符

sendDigitalPortPair(byte pin, int value)

发送数字端口作为顶层网域名称

sendSysex(byte command, byte bytec, byte* bytev)

发送一个任意的字节数组的命令

sendString(const char* string)

发送一个字符串至主机电脑

sendString(byte command, const char* string)

通过使用一个自定义的命令类型发送一个字符串到主机电脑

接收消息

available()

检查是否有任何传入的消息在缓冲

processInput()

处理从缓冲区传入的消息,发送数据至任意已注册的回调函数

attach(byte command, callbackFunction myFunction)

附上一个函数至传入消息类型

detach(Bytes command )

从传入消息类型中分离出一个函数

回调函数

为了给信息类型附上一个函数,你的函数必须匹配标准的回调函数。
In order to attach your function to a message type, your function must match the standard callback function.

目前有三种类型的回调函数:generic, string, sysex。
There are currently three types of callback functions in Firmata: generic, string, and sysex.

*generic
void callbackFunction(byte pin, int value);

*system_reset
void systemResetCallbackFunction(void);

*string
void stringCallbackFunction(char *myString);

*sysex
void sysexCallbackFunction(byte pin, byte byteCount, byte *arrayPointer);

*Message Types
These are the various message types that you can attach functions to.
这些是不同的消息类型,您可以附加功能。

*ANALOG_MESSAGE
the analog value for a single pin
模拟值为一个单独端口。

*DIGITAL_MESSAGE
8-bits of digital pin data (one port)
8位数的Pin数据(仅限一个端口)

*REPORT_ANALOG
enable/disable the reporting of analog pin
启用/禁用模拟插口的数据传输

*REPORT_DIGITAL
enable/disable the reporting of a digital port
启用/禁用数据端口的数据传输

*SET_PIN_MODE
change the pin mode between INPUT/OUTPUT/PWM/etc.
在INPUT/OUTPUT/PWM之间转换插口模式

*FIRMATA_STRING
C-style strings, uses stringCallbackFunction for the function type
C样式的字符串,使用stringCallbackFunction函数类型

*SYSEX_START
generic, arbitrary length messages (via MIDI SysEx protocol), uses sysexCallbackFunction for the function type
通用的、任意长度的消息(通过MIDI SysEx协议),则使用sysexCallbackFunction函数类型

*SYSTEM_RESET
message to reset firmware to its default state, uses systemResetCallbackFunction for the function type
消息重置固件到默认状态,使用systemResetCallbackFunction函数类型

例子

这个例子展示了如何发送和接收模拟消息Firmata使用。 This example shows how to send and receive analog messages using Firmata.

#include <Firmata.h>

byte analogPin;

void analogWriteCallback(byte pin, int value) {

  pinMode(pin,OUTPUT);
  analogWrite(pin, value);

}

void setup() {

  Firmata.setFirmwareVersion(0, 1);
  Firmata.attach(ANALOG_MESSAGE, analogWriteCallback);
  Firmata.begin();

}

void loop() {

  while(Firmata.available()) {
      Firmata.processInput();
  }
  for(analogPin = 0; analogPin < TOTAL_ANALOG_PINS; analogPin++) {
      Firmata.sendAnalog(analogPin, analogRead(analogPin)); 
  }

}

Reference Home

reference/library/firmata.txt · 最后更改: 2023/06/07 04:24 由 127.0.0.1