ผมพยายามทำนานมากแล้วครับยังไม่ได้ครับ
คือผมต้องการที่จะกด a แล้วให้ servo หมุน 10 องศาครับ แล้วกด b -10องศาครับ
#include <SoftwareSerial.h>
#include <Servo.h>
Servo myservo;
int pos = 0;
SoftwareSerial mySerial(10,11);
void setup()
{
myservo.attach(4);
Serial.begin(57600);
mySerial.begin(57600);
}
void loop(){
if(mySerial.available())
{
char j = mySerial.read();
if (j == 'a');
{
( pos += 1 );
myservo.write(pos);
}
if (j == 'b');
{
( pos -= 1 );
myservo.write(pos);
}
}
// for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees
// {
// myservo.write(pos); // tell servo to go to position in variable 'pos'
// delay(15); // waits 15ms for the servo to reach the position
// }
// for(pos = 180; pos>=1; pos-=1)// goes from 180 degrees to 0 degrees
// {
// myservo.write(pos); // tell servo to go to position in variable 'pos'
// delay(150); // waits 15ms for the servo to reach the position
// }
Serial.println("Hardware & Software Serial");
delay(10000);
}
โค๊ดไม่ error ครับ แต่กด a b แล้วเงียบครับ 5555
รบกวนผู้รู้ช่วยดูให้ทีครับ ขอบคุณมากครับ
รบกวนการช่วยดู โค็ด Arduino ให้หน่อยครับ เรื่องการคุบ Servo ครับ
คือผมต้องการที่จะกด a แล้วให้ servo หมุน 10 องศาครับ แล้วกด b -10องศาครับ
#include <SoftwareSerial.h>
#include <Servo.h>
Servo myservo;
int pos = 0;
SoftwareSerial mySerial(10,11);
void setup()
{
myservo.attach(4);
Serial.begin(57600);
mySerial.begin(57600);
}
void loop(){
if(mySerial.available())
{
char j = mySerial.read();
if (j == 'a');
{
( pos += 1 );
myservo.write(pos);
}
if (j == 'b');
{
( pos -= 1 );
myservo.write(pos);
}
}
// for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees
// {
// myservo.write(pos); // tell servo to go to position in variable 'pos'
// delay(15); // waits 15ms for the servo to reach the position
// }
// for(pos = 180; pos>=1; pos-=1)// goes from 180 degrees to 0 degrees
// {
// myservo.write(pos); // tell servo to go to position in variable 'pos'
// delay(150); // waits 15ms for the servo to reach the position
// }
Serial.println("Hardware & Software Serial");
delay(10000);
}
โค๊ดไม่ error ครับ แต่กด a b แล้วเงียบครับ 5555
รบกวนผู้รู้ช่วยดูให้ทีครับ ขอบคุณมากครับ