Host GPIO

The emulator does not provide any low-level GPIO support, this is handled at a higher level using DigitalHooks.

API Documentation

class DigitalHooks

Class to customise behaviour for digital functions.

Note

By default, actions get output to console but this can get very busy. The easiest way to change the behaviour is by sub-classing DigitalHooks and passing the new class instance to setDigitalHooks().

Public Functions

virtual void badPin(const char *function, uint16_t pin)

Report invalid pin number.

Parameters:
  • function – Name of function which was called

  • pin – The pin number

virtual bool pinMode(uint16_t pin, uint8_t mode)

Set pin mode.

Parameters:
  • pin – Has already been range checked

  • mode

Return values:

true – if mode can be set for this pin, will be stored

virtual void digitalWrite(uint16_t pin, uint8_t val)

Change pin output.

Parameters:
  • pin – Has already been range checked

  • val – New pin value

virtual uint8_t digitalRead(uint16_t pin, uint8_t mode)

Read pin state.

Parameters:
  • pin – Has already been range checked

  • mode – The currently set mode for this pin

  • val – State for pin

virtual void pullup(uint16_t pin, bool enable)

Set or clear pullup state for a pin.

Parameters:
  • pin – Has already been range checked

  • enable – true for pullup, false for no pullup

virtual unsigned long pulseIn(uint16_t pin, uint8_t state, unsigned long timeout)

Measure duration of pulse on GPIO.

Parameters:
  • pin – GPIO to measure

  • state – State of pulse to measure [HIGH | LOW]

  • timeout – Maximum duration of pulse

Return values:

unsigned – long Pulse duration in microseconds

virtual uint16_t analogRead(uint16_t pin)

Sample analogue input.

Parameters:

pin – GPIO to read

Return values:

uint16_t – Sample value