A new “BlinkPlug” class has been added to the Ports library. The public interface is:
Here is the new “blink_demo” sketch, using a Blink Plug attached to port 3:
This code demonstrates how to turn LEDs 1 and 2 on or off, and how to access buttons 1 and 2 – pushed() will detect a transition from released to pressed (with proper de-bouncing), whereas state() returns the current button state (no de-bouncing logic).
There is some special logic in this class, because each LED/button pair on the Blink Plug is connected to the same I/O line. Reading out the button requires briefly turning the LED off, and the I/O line should never be set to drive the output high. These details are conveniently hidden in the above class.
An updated Ports library has been checked into the source code repository.
Note: the repository location has changed, see the CODE page for details.