Как управлять серводвигателем с помощью Windows Remote Arduino?
Я играл с новыми библиотеками Remote Wiring на Windows Remote Arduino и не смог управлять сервоприводом - в библиотеке есть опция "PinMode.Servo" - но двигатель не работает надежно, иногда совсем нет,
Код ниже
namespace UniversalBlink
{открытый закрытый частичный класс 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);
}
}
}
Я в растерянности относительно того, куда идти отсюда.
0 ответов
Код использует Bluetooth или Serial (через USB) для управления Arduino.