void AnalogInputFirmata::handleCapability(byte pin) { if (IS_PIN_ANALOG(pin)) { Firmata.write(PIN_MODE_ANALOG); Firmata.write(10); // 10 = 10-bit resolution } }
void AnalogInputFirmata::report() { byte pin, analogPin; /* 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)); } } } }
boolean handleAnalogFirmataSysex(byte command, byte argc, byte* argv) { if (command == ANALOG_MAPPING_QUERY) { Firmata.write(START_SYSEX); Firmata.write(ANALOG_MAPPING_RESPONSE); for (byte pin = 0; pin < TOTAL_PINS; pin++) { Firmata.write(IS_PIN_ANALOG(pin) ? PIN_TO_ANALOG(pin) : 127); } Firmata.write(END_SYSEX); return true; } return false; }
boolean AnalogInputFirmata::handlePinMode(byte pin, int mode) { if (IS_PIN_ANALOG(pin)) { if (mode == PIN_MODE_ANALOG) { reportAnalog(PIN_TO_ANALOG(pin), 1); // turn on reporting if (IS_PIN_DIGITAL(pin)) { pinMode(PIN_TO_DIGITAL(pin), INPUT); // disable output driver } return true; } else { reportAnalog(PIN_TO_ANALOG(pin), 0); // turn off reporting } } return false; }