//pin will not correspond to pin number for analog input pins being used
 //for digitalWrite
 public bool DigitalWrite(int pin, bool on)
 {
     try
     {
         ArduinoCommand cmd = new ArduinoCommand()
         {
             Command = Command.DigitalWrite,
             NumberOfReturnedBytes = 0
         };
         cmd.AddParameter(pin);
         cmd.AddParameter(on ? 1: 0);
         byte[] toWrite = cmd.GetCommandBytes();
         stream.Write(toWrite, 0, toWrite.Length);
         return(true);
     }
     catch (Exception) { return(false); }
 }
 public bool VerticalStabilize(int verticalLeftPwr, int verticalRightPwr)
 {
     try
     {
         ArduinoCommand command = new ArduinoCommand()
         {
             Command = Command.VerticalStabilize,
             NumberOfReturnedBytes = 0
         };
         int verticalSpeed = ((verticalLeftPwr + verticalRightPwr) / 2) - 1500;
         int rollPos       = (verticalLeftPwr - verticalRightPwr) / 2;
         command.AddParameter(verticalSpeed);
         command.AddParameter(rollPos);
         byte[] toWrite = command.GetCommandBytes();
         stream.Write(toWrite, 0, toWrite.Length);
         return(true);
     }
     catch (Exception) { return(false); }
 }
 public bool SetThruster(Thrusters thruster, int value)
 {
     try
     {
         ArduinoCommand command = new ArduinoCommand()
         {
             Command = Command.SetThruster,
             NumberOfReturnedBytes = 0
         };
         command.AddParameter((int)thruster);
         command.AddParameter(value);
         {
             byte[] toWrite = command.GetCommandBytes();
             stream.Write(toWrite, 0, toWrite.Length);
             return(true);
         }
     }
     catch (Exception) { return(false); }
 }
        public bool SetServoSpeed(Servos servo, int speed)
        {
            ArduinoCommand cmd = new ArduinoCommand()
            {
                Command = Command.SetServoSpeed,
                NumberOfReturnedBytes = 0
            };

            cmd.AddParameter((int)servo);
            cmd.AddParameter(speed);
            try
            {
                byte[] toWrite = cmd.GetCommandBytes();
                stream.Write(toWrite, 0, toWrite.Length);
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }