This seems too simplistic to have gone unnoticed before now… Am I missing something? It appears that Read() always returns false. I’m using the latest 4.2 firmware. I know I can and should be keeping this state in a variable but I stumbled across this and left it as an example.
public partial class Program
{
private DigitalOutput p;
// This method is run when the mainboard is powered up or reset.
void ProgramStarted()
{
var relayState = true;
p = extender.SetupDigitalOutput(Socket.Pin.Three, false);
button.ButtonPressed += (sender, state) =>
{
relayState = p.Read();
Debug.Print(relayState.ToString()); // Always prints "false".
p.Write(!relayState);
};
}
}