獨木舟kayak(arduino)
#include <SoftwareSerial.h>
#include <Wire.h>
#include <Servo.h>
Servo servo_2;
Servo servo_3;
SoftwareSerial CAR_BT(4,5); //定義 tX 及rX 腳位
void setup()
{
servo_2.attach(2);
servo_3.attach(3);
Serial.begin(9600); //Arduino起始鮑率:9600
CAR_BT.begin(9600); //藍牙鮑率:9600
}
void s() {
servo_2.write(90);
servo_3.write(90);
}
void a1() {
servo_2.write(60);
}
void a2() {
servo_2.write(120);
}
void a3() {
servo_2.write(90);
}
void a5() {
servo_3.write(110);
}
void a6() {
servo_3.write(70);
}
void a7() {
servo_3.write(90);
}
void f() {
a5();
delay(700);
a2();
delay(700);
a6();
delay(700);
a1();
delay(700);
}
void b() {
a6();
delay(700);
a2();
delay(700);
a5();
delay(700);
a1();
delay(700);
}
void r() {
a5();
delay(700);
a2();
delay(700);
a7();
delay(700);
a1();
delay(700);
}
void l() {
a6();
delay(700);
a1();
delay(700);
a7();
delay(700);
a2();
delay(700);
}
void loop()
{
int inSize;
char input;
if( (inSize = (CAR_BT.available())) > 0) { //讀取藍牙訊息
Serial.print("size = ");
Serial.println(inSize);
Serial.print("Input = ");
Serial.println(input=(char)CAR_BT.read());
if( input == 'f' ) {for (int count = 0; count < 5; count++)
f();
}
if( input == 'l' ) {for (int count = 0; count < 3; count++)
l();
}
if( input == 'r' ) {for (int count = 0; count < 3; count++)
r();
}
if( input == 'b' ) {for (int count = 0; count < 3; count++)
b();
}
if( input == 's' ) {
s();
}
}
}