Skip to content

Turn pin on/off #107

@bodovix

Description

@bodovix

I've been experimenting with this library but haven't been able to find a direct turn pin on or off? we can toggle or blink. but these require being me to be aware of the pins current state before toggling.
To achieve this I ended up using the extension methods below.
Is there a better way to do this currently? or is this something that we would maybe need?
(couldn't get the 'code text 'thing formatting properly...)

public static class GwydsGreatExtensionMethods
{
public static void TurnOn(this GpioConnection gpioConn, ProcessorPin pin)
{
GpioConnectionDriver driver = new GpioConnectionDriver();
if (driver.Read(pin) == false)
{
gpioConn[pin] = !gpioConn[pin];
Console.WriteLine("Light Turned on");
}
else
{
//already on. no need to toggle
Console.WriteLine("already on.");
}
}
public static void TurnOff(this GpioConnection gpioConn, ProcessorPin pin)
{
GpioConnectionDriver driver = new GpioConnectionDriver();
if (driver.Read(pin) == true)
{
gpioConn[pin] = !gpioConn[pin];
Console.WriteLine("Light Turned off");
}
else
{
Console.WriteLine("already off.");
}
}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions