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;
}
Exemple #2
0
void irLineSensorClass::reportValue(int sequenceId, Stream * stream)  // send the value of the given device
{
   if( sequenceId < nbrElements) {
      int pin = pins[sequenceId+1]; // the first pin is the control pin
      pin = PIN_TO_ANALOG(pin); // convert digital number to analog
      int value = analogRead(pin);   
      stream->print(value);
    }
}
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;
}