-
Notifications
You must be signed in to change notification settings - Fork 1
/
BOTMOVE.ino
57 lines (48 loc) · 1.14 KB
/
BOTMOVE.ino
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
#include <SoftwareSerial.h>
SoftwareSerial BTSerial(10, 11); // RX, TX
void setup()
{pinMode(3,OUTPUT);
pinMode(5,OUTPUT);
pinMode(6,OUTPUT);
pinMode(9,OUTPUT);
pinMode(8,OUTPUT);
digitalWrite(8,HIGH);
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
Serial.println("Ready!");
// set the data rate for the SoftwareSerial port
// for HC-05 use 38400 when poerwing with KEY/STATE set to HIGH on power on
BTSerial.begin(38400);
}
int spd;
String input;
int a;
void loop() // run over and over
{
if (BTSerial.available()>0)
{
input = BTSerial.readString() ;
// Serial.write(input);
a = input.toInt();
sspd=(a*50/350) ;
analogWrite(5,spd);
analogWrite(3,0);
analogWrite(6,spd);
analogWrite(9,0);
delay(10);
if(spd < 20 && spd > 0){
analogWrite(3,0);
analogWrite(5,0);
analogWrite(6,0);
analogWrite(9,0);
}
Serial.print(a);
Serial.print(" ");
Serial.println(input);
}
if (Serial.available())
BTSerial.write(Serial.read());
}