-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathServo_BT_Control
More file actions
75 lines (56 loc) · 2.21 KB
/
Servo_BT_Control
File metadata and controls
75 lines (56 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/****************************************************************************
* Copyright(C) : National Central University ROD Lab Jen Hao Chen (Howard)
* Create Date : 2014/07/28 by Howard Chen
* Modified Date: 2014/09/25 by Howard Chen
* Abstract : This program will test the connection of the phone and Arduino borad via
bluetooth module. This program will let the led on Arduino borad to turn on
and turn off depends on the botton that you touch on phone.
* Reference : None
/*****************************************************************************/
#include <Servo.h>
Servo myservo;
byte decide = 0;
void setSpeed(int speed){
int val = map(speed,0,500,0,180);
myservo.write(val);
}
void setup() {
Serial.begin(9600);
myservo.attach(9);
}
void loop() {
Serial.println("System ready!!! Hit 1");
do{if(Serial.read()=='1')
break;
}while(1);
int speed;
Serial.println("Throttle up");
for(speed = 190; speed<=195; speed+=1){
setSpeed(speed);
Serial.println(speed);
delay(100);
}
setSpeed(190);
Serial.println(speed);
Serial.println(decide);
do{
if(Serial.available()){
if(Serial.read()>decide){
decide = Serial.read();
Serial.print("decide =");
Serial.println(decide, DEC);
speed = speed+3;
setSpeed(speed);
Serial.print("speed =");
Serial.println(speed);} //if
else if(Serial.read()<decide){
decide = Serial.read();
Serial.print("decide =");
Serial.println(decide, DEC);
speed = speed-3;
setSpeed(speed);
Serial.print("speed =");
Serial.println(speed);} //else if
} // for if(Serial.available()
}while(1);
}