使用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
- }
復制代碼 |