I am working on a module using the Breadboard X1 on a FEZ Spider running 4.3. Among other things, the module makes use of the four built-in LEDs, attached to four GPIO pins, and I am writing a Gadgeteer module driver that provides application control of the LEDs (among other things).
Because I anticipate a lot of toggling by the application of LED states, which requires knowing the current state of the toggled LED, I was wondering which of the following would be better performing:
- GTI.DigitalOutput Read() to get the current state.
- Keeping a private bool that contains the current state, and reading it when needed.
The latter assumes that all changes to the LED states are done through the module’s driver interface, so the bool should always be in sync with the actual LED state.
I guess what I’m getting at is this: Is reading a GPIO pin via Read() more expensive than reading a variable out of memory? Or are they roughly the same?