Control Servo With Visual Basic 2008
-
Upload
juan-pablo-espinal -
Category
Documents
-
view
72 -
download
2
Transcript of Control Servo With Visual Basic 2008
Control servo with Visual Basic 2008
http://forum.arduino.cc/index.php/topic,21066.0.html
Visual Basic 2008 code:
Private Sub TrackBar1_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrackBar1.Scroll If RadioButton2.Checked = True Then SerialPort1.Write(TrackBar1.Value) End If End Sub
Arduino code:
#include <Servo.h> Servo myservo;
int SerialValue = 0; void setup() { myservo.attach(9); Serial.begin(9600);} void loop() { SerialValue = Serial.read(); myservo.write(SerialValue); delay(15); }
AEDUINO_PROGRAM
int select;int val;int val2;int servoValue = 0;char inData[12];int index = 0;bool started = false;bool ended = false;int pos;
#include <Servo.h> Servo myservo;
void setup() { myservo.attach(9); // attaches the servo on pin 9 to the servo object }
void loop(){ if(Serial.available() > 0) { while(Serial.available() > 0) { char aChar = Serial.read(); if(aChar == '<') { index = 0; inData[index] = '\0'; // Null out the array started = true; ended = false; } if(aChar != '>' && started && !ended) { inData[index] = aChar; index++; inData[index] = '\0'; } if(aChar == '>') { ended = true; started = false; }
if(aChar == ':') { select = pos; pos = 0; val = 1; } if(ended && !started) { servoValue = atoi(inData); myservo.write(pos); delay(15); ended = false; // Set up for the next packet } else{ select = Serial.read(); val2 = Serial.read(); if(val = 1){ val2 = Serial.read(); val2 * 100; pos = val2; } else if(val = 2){ val2 = Serial.read(); val2 * 10; pos = pos + val2; } else if(val = 3){ val2 = Serial.read(); pos = pos + val2; val = 0; } } } }}
VB_PROGRAM
Private Sub TrackBar1_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrackBar1.Scroll Dim value As Integer SerialPort1.Write("<") If TrackBar1.Value.ToString.Count = 1 Then SerialPort1.Write("1") SerialPort1.Write(":") SerialPort1.Write(TrackBar1.Value)
ElseIf TrackBar1.Value.ToString.Count = 2 Then SerialPort1.Write("2") SerialPort1.Write(":") SerialPort1.Write(TrackBar1.Value.ToString.First) SerialPort1.Write(TrackBar1.Value.ToString.Last) ElseIf TrackBar1.Value.ToString.Count = 3 Then SerialPort1.Write("3") SerialPort1.Write(":") SerialPort1.Write(TrackBar1.Value.ToString.First) value = TrackBar1.Value - 100 SerialPort1.Write(value - Val(TrackBar1.Value.ToString.Last)) SerialPort1.Write(TrackBar1.Value.ToString.Last) End If SerialPort1.Write(">") End Sub
VB_PROGRAM
Private Sub TrackBar1_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrackBar1.Scroll SerialPort1.Write("<") SerialPort1.Write(TrackBar1.Value.ToString) SerialPort1.Write(">") End Sub
ARDUINO_PROGRAM
int servoValue = 0;char inData[12];int index = 0;bool started = false;bool ended = false;
#include <Servo.h> Servo myservo;
void setup() { myservo.attach(9); // attaches the servo on pin 9 to the servo object }
void loop(){ if(Serial.available() > 0) { while(Serial.available() > 0) { char aChar = Serial.read(); if(aChar == '<') { index = 0; inData[index] = '\0'; // Null out the array started = true; ended = false; } if(aChar != '>' && started && !ended) { inData[index] = aChar; index++; inData[index] = '\0'; } if(aChar == '>') { ended = true; started = false;
} if(ended && !started) { servoValue = atoi(inData); myservo.write(servoValue); delay(15); ended = false; // Set up for the next packet } } } }
http://forum.arduino.cc/index.php/topic,40250.0.html SERIAL_ARDUINO_VB
http://forum.arduino.cc/index.php/topic,16644.0.htmlRGB LED with VB 2008 and transistors
http://www.youtube.com/watch?v=GnKF99tIuN8Carrito Robot Inalámbrico BlueTooth Visual Basic 2010
http://marc-tetrapod.blogspot.ca/2012/10/arduino-ssc-32-servo.html --> Arduino + SSC 32 + Servo
THEO_JANSEN_MACHINE