简体   繁体   English

如何使用Windows Remote Arduino控制伺服电机?

[英]How to control a servo motor with Windows Remote Arduino?

I've been playing with the new Remote Wiring libraries on Windows Remote Arduino and I have been unable to control a servo - there is a "PinMode.Servo" option in the library - but the motor does not move reliably, sometimes not at all. 我一直在使用Windows Remote Arduino上的新远程接线库,但无法控制伺服器-库中有一个“ PinMode.Servo”选项-但电机不能可靠地移动,有时根本无法移动。

The code is below 代码如下

namespace UniversalBlink

{ public sealed partial class MainPage : Page { private bool useBluetooth = true; {公共密封的部分类MainPage:页面{private bool useBluetooth = true;

    BluetoothSerial bluetooth;
    UsbSerial usb;

    RemoteDevice arduino;

    public MainPage()
    {
        this.InitializeComponent();

        if (useBluetooth)
        {
            bluetooth = new BluetoothSerial("HC-06");
            arduino = new RemoteDevice(bluetooth);
            bluetooth.ConnectionEstablished += OnConnectionEstablished;
            //these parameters don't matter for bluetooth
            bluetooth.begin(0, 0);
        }
        else
        {
            usb = new UsbSerial("VID_2341", "PID_0043");   //I've written in my device D directly
            var test = UsbSerial.listAvailableDevicesAsync();                

            arduino = new RemoteDevice(usb);
            usb.ConnectionEstablished += OnConnectionEstablished;
            usb.begin(57600, SerialConfig.SERIAL_8N1);
        }
    }

    private void OnConnectionEstablished()
    {
        //enable the buttons on the UI thread!
        var action = Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, new Windows.UI.Core.DispatchedHandler(() => {
            OnButton.IsEnabled = true;
            OffButton.IsEnabled = true;
            arduino.pinMode(9, PinMode.SERVO);
        }));
    }       

    private async void OnButton_Click(object sender, RoutedEventArgs e)
    {
        arduino.analogWrite(9, 0);
    }

    private async void OffButton_Click(object sender, RoutedEventArgs e)
    {
        arduino.analogWrite(9, 140);
    }


}

} }

I'm at a loss as to where to go from here. 我不知道该从哪里去。

该代码使用蓝牙或串行(通过USB)来控制Arduino。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM