Controlling output
The relay is connected to our digital output pin 9
on the Arduino board. As such, controlling it is a simple call to the digitalWrite()
method on our arduino
object. Since we will need to perform this control action from various locations in code in later chapters, we'll create a method for it:
internal async Task SetOutput(bool On, string Actor) { if (this.arduino != null) { this.arduino.digitalWrite(9, On ? PinState.HIGH : PinState.LOW);
The first parameter simply states the new value of the control parameter. We'll add a second parameter that describes who is making the requested change. This will come in handy later, when we allow online users to change control parameters.
Persisting control parameter states
If the device reboots for some reason, for instance after a power outage, it's normally desirable that it returns to the state it was in before it shut down. For this, we need to persist the output value. We can use the object database...