thanks andrew! it worked perfectly!
ok now i want to try something else!
i want to send different commands to each of the two servos repectively via a textbox and button in vb.. so lets say servo 1 to move 180 degrees then i would type 1180.. servo 2 to move 90 degrees then i would type 290 ya? is this the way to control multiple servos?
i tried some code already and ofcourse it doesnt work! lol.. can some1 take a look please..
this is the vb.net part
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim myString As String = TextBox1.Text
Dim head As Byte = CByte(myString.Substring(1, 1))
Dim butt As Byte = CByte(myString.Substring(1))
Dim buffer(1) As Byte
buffer(0) = head
buffer(1) = butt
port.Write(buffer, 0, 2)
End Sub
this is the arduino part:
int servoPin1 = 2; // Control pin for servo motor
int servoPin2 = 9;
int minPulse = 600; // Minimum servo position
int maxPulse = 3000; // Maximum servo position
int pulse1 = 0; // Amount to pulse the servo
int pulse2 = 0;
long lastPulse = 0; // the time in milliseconds of the last pulse
int refreshTime = 20; // the time needed in between pulses
byte input[1];
int count=0;
void setup() {
pinMode(servoPin1, OUTPUT); // Set servo pin as an output pin
pinMode(servoPin2, OUTPUT);
pulse1 = minPulse; // Set the motor position value to the minimum
pulse2 = minPulse;
Serial.begin(9600);
}
void loop()
{
if (Serial.available()>0)
{
while(Serial.available())
{
input[count++]=Serial.read();
}
}
count=0;
if(input[0]==1)
{
pulse1 = map(input[1],0,180,minPulse,maxPulse);
}
if(input[0]==2)
{
pulse2=map(input[1],0,180,minPulse,maxPulse);
}
// pulse the servo again if rhe refresh time (20 ms) have passed:
if (millis() - lastPulse >= refreshTime)
{
digitalWrite(servoPin1, HIGH); // Turn the motor on
delayMicroseconds(pulse1); // Length of the pulse sets the motor position
digitalWrite(servoPin1, LOW); // Turn the motor off
digitalWrite(servoPin2, HIGH);
delayMicroseconds(pulse2);
digitalWrite(servoPin2, LOW);
lastPulse = millis(); // save the time of the last pulse
}
}
somebody please give me some pointers.. nothing i do in programming ever works.. lol!