Hello, I am taking a program I built for FEZ Panda 3 using NETMF and moving it to one of the new FEZ boards running TinyCLR.
On NETMF, there was an easy way to toggle an output, using the OutputPort class.
static OutputPort HEARTBEAT_IND = new OutputPort(FEZPandaIII.Gpio.Led4, false);
then, when I toggle it,
while (true)
{
HEARTBEAT_IND.Write(!HEARTBEAT_IND.Read());
Thread.Sleep(400);
}
/* I am moving it over from NETMF to TinyCLR because the available classes of FEZ boards in the definition of an OutputPort do not include the FEZ. Error (Type or Namespace ‘FEZ’ does not exist in the namespace GHI.Pins) */
When I write for TinyCLR , I need to use the GpioPin type
static GpioPin HEARTBEAT_IND = GpioController.GetDefault().OpenPin(GHIElectronics.TinyCLR.Pins.FEZ.GpioPin.Led2);
If I attempt to toggle the same way , it flags an error that the operator ! cannot be applied to operand of type GpioPin.
This:
HEARTBEAT_IND.Write(!HEARTBEAT_IND.Read());
I tried casting the return from HEARTBEAT_IND.Read(); without success
HEARTBEAT_IND.Write((bool)!HEARTBEAT_IND.Read());
Error ----> Cannot convert type GpioPinValue to bool
Instead, I have to run through an if else statement to make the same function happen.
if(HEARTBEAT_IND.Read() == GpioPinValue.Low)
{
HEARTBEAT_IND.Write(GpioPinValue.High);
}
else
{
HEARTBEAT_IND.Write(GpioPinValue.Low);
}
I cannot imagine a simple function like this is lost in TinyCLR, so it must be something I am missing.
Any help is appreciated.
Thanks