Hi all
I have project that controlled a remote car using VB connected to arduino Via bluetooth
I have a trackbar to give the value to the servo
And i have a button to give the PWM value to the motor
this is the code that i used for the servo (ps: i take this code from "Control servo with Visual Basic 2008 - Interfacing - Arduino Forum" i tried it and it works)
#include <Servo.h>
Servo myservo;
int pos=0;
void setup()
{
Serial.begin(9600);
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop()
{
if(Serial.available() > 0)
{
char aChar = Serial.read();
if(aChar == '<')
{
pos = 0;
do{
while(Serial.available() <1)
; // wait for a character
aChar = Serial.read();
if(aChar >= '0' && aChar <= '9') // is ch a number?
pos = pos * 10 + aChar - '0'; // yes, accumulate the value
}
while(aChar != '>');
myservo.write(pos);
pos = 0;
}
}
}
And the VB code
Private Sub TrackBar1_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrackBar1.Scroll
Label8.Text = String.Format("Degree: {0}", TrackBar1.Value)
If SerialPort1.IsOpen = True Then
SerialPort1.Write("<")
SerialPort1.Write(TrackBar1.Value.ToString)
SerialPort1.Write(">")
End If
End Sub
I dont know the part of this code
char aChar = Serial.read();
if(aChar == '<')
{
pos = 0;
do{
while(Serial.available() <1)
; // wait for a character
aChar = Serial.read();
if(aChar >= '0' && aChar <= '9') // is ch a number?
pos = pos * 10 + aChar - '0'; // yes, accumulate the value
}
can you explain to me?
and is it possible to add PWM value using button (if i press the button twice the value increasing by 20)?
Im confuse about how to parse the data between servo data from Trackbar and PWM data from button.
I want to send data as a packet and my arduino detect the value from each trackbar value to servo or button value to PWM motor.
Thank you!!!