Quote:
Imports System.IO
Imports System.IO.Ports
Imports System.Threading
Public Class Form1
Shared _continue As Boolean
Shared _serialPort As SerialPort
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
SerialPort1.Close()
SerialPort1.PortName = "com37" 'you need to check which com port your arduino is using, and change them if you need
SerialPort1.BaudRate = 9600
SerialPort1.DataBits = 8
SerialPort1.Parity = Parity.None
SerialPort1.StopBits = StopBits.One
SerialPort1.Handshake = Handshake.None
SerialPort1.Encoding = System.Text.Encoding.Default
End Sub
Private Sub btn90L_Click_1(sender As System.Object, e As System.EventArgs) Handles btn90L.Click
SerialPort1.Open()
SerialPort1.Write("0")
SerialPort1.Close()
End Sub
And on the Arduino side, you just upload this (it's incomplete, I figured everything out, got it working and then left it at the thumb, but this is a complete example, easy to modify and update)
Quote:
#include <Servo.h>
//Assign Servo's (could be done in an array if you prefer)
Servo thumb;
Servo indexf;
Servo middlef;
Servo ringf;
Servo pinkyf;
void setup()
{
thumb.attach(9); // attaches the servo on pin 9 to the thumb servo
Serial.begin(9600); //begins serial communication
}
void loop()
{
int pos;
if (Serial.available()){
delay(100);
while(Serial.available()>0){
pos=Serial.read(); //reads the value sent from Visual Basic
if(pos=='0')
thumb.write(90); //rotates the servo 90 degrees (Left)
else if(pos=='1')
thumb.write(-90); //rotates the servo 90 degrees (right)
else if(pos=='2')
thumb.write(180); //rotates the servo 180 degrees (Left)
else if(pos=='3')
thumb.write(-180); //rotates the servo 180 degrees (right)
else if(pos=='4')
thumb.write(0); //center servo.
}
}
}