Prinzipiell hab ich nur die Mega Multiserial in die Standard Firmata reinkopiert. Änderungen sind Farbig markiert. Änderungen also nur in der Setup und Loop.
/*
/*==============================================================================
- SETUP()
============================================================================/
void setup()
{
byte i;
Firmata.setFirmwareVersion(2, 2);
Firmata.attach(ANALOG_MESSAGE, analogWriteCallback);
Firmata.attach(DIGITAL_MESSAGE, digitalWriteCallback);
Firmata.attach(REPORT_ANALOG, reportAnalogCallback);
Firmata.attach(REPORT_DIGITAL, reportDigitalCallback);
Firmata.attach(SET_PIN_MODE, setPinModeCallback);
Firmata.attach(START_SYSEX, sysexCallback);
// TODO: load state from EEPROM here
/* these are initialized to zero by the compiler startup code
for (i=0; i < TOTAL_PORTS; i++) {
reportPINs = false;
_ portConfigInputs = 0;_
_ previousPINs = 0;
* }
/_
for (i=0; i < TOTAL_PINS; i++) {
* if (IS_PIN_ANALOG(i)) {
_ // turns off pullup, configures everything*
* setPinModeCallback(i, ANALOG);
} else {
// sets the output to 0, configures portConfigInputs*
* setPinModeCallback(i, OUTPUT);
}
}
// by defult, do not report any analog inputs*
* analogInputsToReport = 0;
Firmata.begin(57600);
Serial1.begin(57600);
Serial2.begin(57600);
Serial3.begin(57600);
/ send digital inputs to set the initial state on the host computer,
* since once in the loop(), this firmware will only send on change /_
for (i=0; i < TOTAL_PORTS; i++) {
_ outputPort(i, readPort(i, portConfigInputs), true);
}
}
/==============================================================================
* LOOP()
============================================================================/
void loop()
{
* if (Serial1.available()) {
int inByte = Serial.read();
Serial1.print(inByte, BYTE);
Serial2.print(inByte, BYTE);
Serial3.print(inByte, BYTE);
}*_
* byte pin, analogPin;*
_ /* DIGITALREAD - as fast as possible, check for changes and output them to the_
_ * FTDI buffer using Serial.print() /
checkDigitalInputs();
/ SERIALREAD - processing incoming messagse as soon as possible, while still_
_ * checking digital inputs. /
while(Firmata.available())
Firmata.processInput();
/ SEND FTDI WRITE BUFFER - make sure that the FTDI buffer doesn't go over_
_ * 60 bytes. use a timer to sending an event character every 4 ms to_
_ * trigger the buffer to dump. /
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) && pinConfig[pin] == ANALOG) {
analogPin = PIN_TO_ANALOG(pin);
_ if (analogInputsToReport & (1 << analogPin)) {
Firmata.sendAnalog(analogPin, analogRead(analogPin));
}
}
}
}
}*_