public async Task <bool> PulsePinAsync(byte pin, ArduinoPinValue offValue, TimeSpan onDuration, TimeSpan offDuration) { bool returnValue = false; byte[] registerId = BitConverter.GetBytes((uint)ArduinoRegister.PulsePin); uint highDurationInMilliseconds = (ushort)onDuration.TotalMilliseconds; byte[] highDurationBytes = BitConverter.GetBytes(highDurationInMilliseconds); uint lowDurationInMilliseconds = (ushort)offDuration.TotalMilliseconds; byte[] lowDurationBytes = BitConverter.GetBytes(lowDurationInMilliseconds); await this.WriteAsync(new byte[] { registerId[0], registerId[1], pin, (byte)offValue, highDurationBytes[0], highDurationBytes[1], highDurationBytes[2], highDurationBytes[3], lowDurationBytes[0], lowDurationBytes[1], lowDurationBytes[2], lowDurationBytes[3] }); // *** // *** Check if the call was successful // *** if (await this.CheckResult()) { returnValue = true; } return(returnValue); }
public async Task <bool> DigitalWriteAsync(byte pin, ArduinoPinValue value) { bool returnValue = false; byte[] registerId = BitConverter.GetBytes((uint)ArduinoRegister.DigitalWrite); await this.WriteAsync(new byte[] { registerId[0], registerId[1], pin, (byte)value }); // *** // *** Check if the call was successful // *** if (await this.CheckResult()) { returnValue = true; } return(returnValue); }
public async Task<bool> DigitalWriteAsync(byte pin, ArduinoPinValue value) { bool returnValue = false; byte[] registerId = BitConverter.GetBytes((uint)ArduinoRegister.DigitalWrite); await this.WriteAsync(new byte[] { registerId[0], registerId[1], pin, (byte)value }); // *** // *** Check if the call was successful // *** if (await this.CheckResult()) { returnValue = true; } return returnValue; }
public async Task <ArduinoPinValue> DigitalReadAsync(byte pin) { ArduinoPinValue returnValue = ArduinoPinValue.Unknwown; byte[] registerId = BitConverter.GetBytes((uint)ArduinoRegister.DigitalRead); await this.WriteAsync(new byte[] { registerId[0], registerId[1], pin }); // *** // *** Read the result // *** byte[] readBuffer = await this.GetReadBuffer(2); if (await this.CheckResult(readBuffer)) { returnValue = readBuffer[1] == 1 ? ArduinoPinValue.High : ArduinoPinValue.Low; } return(returnValue); }
public async Task <ArduinoPinValue> DigitalRead(byte pin) { ArduinoPinValue returnValue = ArduinoPinValue.Low; byte[] readBuffer = new byte[1]; byte[] registerId = BitConverter.GetBytes((uint)ArduinoRegister.DigitalRead); await this.WriteAsync(new byte[] { registerId[0], registerId[1], pin }); // *** // *** Need a very short delay here for this to work // *** await Task.Delay(1); await this.ReadAsync(readBuffer); if (readBuffer[0] == 1) { returnValue = ArduinoPinValue.High; } return(returnValue); }
public async Task DigitalWrite(byte pin, ArduinoPinValue value) { byte[] registerId = BitConverter.GetBytes((uint)ArduinoRegister.DigitalWrite); await this.WriteAsync(new byte[] { registerId[0], registerId[1], pin, (byte)value }); }
public async Task<bool> PulsePinAsync(byte pin, ArduinoPinValue offValue, TimeSpan onDuration, TimeSpan offDuration) { bool returnValue = false; byte[] registerId = BitConverter.GetBytes((uint)ArduinoRegister.PulsePin); uint highDurationInMilliseconds = (ushort)onDuration.TotalMilliseconds; byte[] highDurationBytes = BitConverter.GetBytes(highDurationInMilliseconds); uint lowDurationInMilliseconds = (ushort)offDuration.TotalMilliseconds; byte[] lowDurationBytes = BitConverter.GetBytes(lowDurationInMilliseconds); await this.WriteAsync(new byte[] { registerId[0], registerId[1], pin, (byte)offValue, highDurationBytes[0], highDurationBytes[1], highDurationBytes[2], highDurationBytes[3], lowDurationBytes[0], lowDurationBytes[1], lowDurationBytes[2], lowDurationBytes[3] }); // *** // *** Check if the call was successful // *** if (await this.CheckResult()) { returnValue = true; } return returnValue; }