I made a C # application to control two servos via USB with Arduino.
When you pull the slider bar, the value is sent to the Arduino, which represent the positions of the servo.
Each servo has his own bar.
C# code :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO.Ports;
using System.Threading;
namespace SERIAL_ANALOG_WRITE
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void bara1_ValueChanged(object sender, EventArgs e)
{
val_bara1.Text = Convert.ToString(bara1.Value);
transmite1();
}
[... do you want the rest of the code???? ...]
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (serialPort1.IsOpen) serialPort1.Close();
}
}
}
Arduino code :
#include <Servo.h>
int v, v1, v2, v3, v4;
Servo servo1;
Servo servo2;
void setup()
{
servo1.attach(9);
servo2.attach(10);
Serial.begin(9600);
}
void loop()
{
if (Serial.available()>0)
{
[... bla-bla-bla...]
}
delay(10);
}