I am a newcomer to C# and I am currently building a windows form application for controlling 2 servo motors by pressing a key on the keyboard.
Communication takes place via serial port and so far everything is ok. The problem arises in engine control.
When I press the key to move the motor in the desired direction and keep it pressed, the servo initially has a small input then after about a second it starts to turn continuously
To use the key interception I use this code:
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if (keyData == Keys.Left)
{
SerialPort01.Write("L");
}
if (keyData == Keys.Right)
{
SerialPort01.Write("R");
}
if (keyData == Keys.Up)
{
SerialPort01.Write("U");
}
if (keyData == Keys.Down)
{
SerialPort01.Write("D");
}
return base.ProcessCmdKey(ref msg, keyData);
}
Can you help me? thanks