我一直在玩 Windows Remote Arduino 上的新远程接线库,但我无法控制伺服 - 库中有一个“PinMode.Servo”选项 - 但电机无法可靠移动,有时根本没有.
代码如下
namespace UniversalBlink
{ public 密封部分类 MainPage : Page { 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);
}
}
}
我不知道从这里去哪里。