簡體   English   中英

如何使用Windows Remote Arduino控制伺服電機?

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

我一直在使用Windows Remote Arduino上的新遠程接線庫,但無法控制伺服器-庫中有一個“ PinMode.Servo”選項-但電機不能可靠地移動,有時根本無法移動。

代碼如下

namespace UniversalBlink

{公共密封的部分類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);
    }


}

}

我不知道該從哪里去。

該代碼使用藍牙或串行(通過USB)來控制Arduino。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM