Пример #1
0
 /// <summary>
 /// Configures the specified pin to behave either as an input or an output.
 /// </summary>
 /// <param name="pin">the number of the pin whose mode you wish to set</param>
 /// <param name="mode">INPUT, OUTPUT, or INPUT_PULLUP</param>
 public void PinMode(int pin, DigitalPinMode mode)
 {
     pinMode(pin, mode);
 }
Пример #2
0
        /// <summary>
        /// Updates pin status/value from status string received from arduino
        /// </summary>
        /// <param name="statusString">String containing digital pin status information</param>
        public void UpdateStatus(string statusString)
        {
            string[] props = statusString.Split(':');

            string valueTemp = ""; //holds value of V property so it can be parsed at the end when pin mode is known

            foreach (string prop in props)
            {
                string key   = prop.Substring(0, 1);
                string value = prop.Substring(1, prop.Length - 1);

                switch (key)
                {
                case "D":
                {
                    int pinNumber = int.Parse(value);
                    if (pinNumber != PinNumber)
                    {
                        throw new Exception(string.Format("Status string '{0}' does not correspond to digita pin {1}", statusString, PinNumber));
                    }
                    break;
                }

                case "M":
                {
                    int modeValue = int.Parse(value);
                    PinMode = (DigitalPinMode)modeValue;
                    break;
                }

                case "V":
                {
                    valueTemp = value; //save to valueTemp because it is possible that PinMode was not yet updated at this point
                    break;
                }

                case "F":
                {
                    Frequency = int.Parse(value);
                    break;
                }

                case "L":
                {
                    Duration = int.Parse(value);
                    break;
                }

                default: throw new Exception(string.Format("Status string '{0}' contains properties which don't belong to analog pin status", statusString));
                }
            }

            if (PinMode == DigitalPinMode.BoolRead || PinMode == DigitalPinMode.BoolWrite)
            {
                BoolValue = valueTemp == "1";
            }
            else if (PinMode == DigitalPinMode.Pwm)
            {
                PwmValue = byte.Parse(valueTemp);
            }
        }
Пример #3
0
 public static void pinMode(int _pin, DigitalPinMode _mode)
 {
 }