使用StandardFirmata实例可以将PC的数据反映到开发板上的引脚上亮灯,但是我想把开发板上的这个结果通过串口发送到另外的开发板上。比如PC发送的数值为2和4,在接到的开发板通过串口将2和4发送出去。一个设计,卡在这了,哪为大能可以给解决一下,代码改了很多回, 不是串口不输出数据,就是输出的数据不对。
123 Hc12
PC————StandardFirmata——-----nano1
nano2
nano3
- void loop()
- {
- byte pin, analogPin;
- /* DIGITALREAD - as fast as possible, check for changes and output them to the
- * FTDI buffer using Serial.print() */
- checkDigitalInputs();
- /* STREAMREAD - processing incoming messagse as soon as possible, while still
- * checking digital inputs. */
- while (Firmata.available())
- Firmata.processInput();
- // TODO - ensure that Stream buffer doesn't go over 60 bytes
- currentMillis = millis();
- if (currentMillis - previousMillis > samplingInterval) {
- previousMillis += samplingInterval;
- /* ANALOGREAD - do all analogReads() at the configured sampling interval */
- for (pin = 0; pin < TOTAL_PINS; pin++) {
- if (IS_PIN_ANALOG(pin) && Firmata.getPinMode(pin) == PIN_MODE_ANALOG) {
- analogPin = PIN_TO_ANALOG(pin);
- if (analogInputsToReport & (1 << analogPin)) {
- Firmata.sendAnalog(analogPin, analogRead(analogPin));
- }
- }
- }
- // report i2c data for all device with read continuous mode enabled
- if (queryIndex > -1) {
- for (byte i = 0; i < queryIndex + 1; i++) {
- readAndReportData(query[i].addr, query[i].reg, query[i].bytes, query[i].stopTX);
- }
- }
- }
- #ifdef FIRMATA_SERIAL_FEATURE
- serialFeature.update();
- #endif
- }
复制代码 |