/// <summary> /// Sets the mode of the specified pin (INPUT or OUTPUT). /// </summary> /// <param name="pin">The arduino pin.</param> /// <param name="mode">Mode Arduino.INPUT Arduino.OUTPUT Arduino.ANALOG Arduino.PWM or Arduino.SERVO .</param> public void PinMode(int pin, ArduinoPinMode mode) { byte[] message = new byte[3]; message[0] = (byte)(SET_PIN_MODE); message[1] = (byte)(pin); message[2] = (byte)(mode); _serialPort.Write(message, 0, message.Length); message = null; }
public ArduinoPin(ArduinoPort port, string pinDescription) { m_port = port; string modeString = pinDescription.Substring(0, 2); switch (modeString) { case "AI": Mode = ArduinoPinMode.AnalogIn; break; case "AO": Mode = ArduinoPinMode.AnalogOut; break; case "DI": Mode = ArduinoPinMode.DigitalIn; break; case "DO": Mode = ArduinoPinMode.DigitalOut; break; default: throw new Exception("Unknown pin mode"); } int posColon = pinDescription.IndexOf(':'); if (posColon < 3) { throw new Exception("Missing pin value or number"); } int posQuote1 = pinDescription.IndexOf('"'); if (posQuote1 < (posColon + 2)) { throw new Exception("Missing pin name or value"); } Number = int.Parse(pinDescription.Substring(2, posColon - 2)); m_value = int.Parse(pinDescription.Substring(posColon + 1, posQuote1 - posColon - 1)); int posQuote2 = pinDescription.LastIndexOf('"'); Name = pinDescription.Substring(posQuote1 + 1, posQuote2 - posQuote1 - 1); }
public async Task <bool> PinModeAsync(byte pin, ArduinoPinMode pinMode) { bool returnValue = false; byte[] registerId = BitConverter.GetBytes((uint)ArduinoRegister.PinMode); await this.WriteAsync(new byte[] { registerId[0], registerId[1], pin, (byte)pinMode }); // *** // *** Check if the call was successful // *** if (await this.CheckResult()) { returnValue = true; } return(returnValue); }
public async Task<bool> PinModeAsync(byte pin, ArduinoPinMode pinMode) { bool returnValue = false; byte[] registerId = BitConverter.GetBytes((uint)ArduinoRegister.PinMode); await this.WriteAsync(new byte[] { registerId[0], registerId[1], pin, (byte)pinMode }); // *** // *** Check if the call was successful // *** if (await this.CheckResult()) { returnValue = true; } return returnValue; }
public async Task PinMode(byte pin, ArduinoPinMode pinMode) { byte[] registerId = BitConverter.GetBytes((uint)ArduinoRegister.PinMode); await this.WriteAsync(new byte[] { registerId[0], registerId[1], pin, (byte)pinMode }); }