我一直在使用Windows Remote Arduino上的新远程接线库而我无法控制伺服 - 有一个" PinMode.Servo"库中的选项 - 但电机不能可靠移动,有时根本不移动。
代码在
之下namespace UniversalBlink
{ 公共密封部分类主页:页面 { 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);
}
}
}
我不知道从哪里开始。
答案 0 :(得分:0)
代码使用蓝牙或串行(通过USB)控制Arduino。