-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.ino
49 lines (46 loc) · 991 Bytes
/
run.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
int rf = 3;
int rb = 5;
int lf = 11;
int lb = 10;
String str;
void setup() {
pinMode(3, OUTPUT);
pinMode(5, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
Serial.begin(9600);
}
void loop() {
if(Serial.available()) {
str = Serial.readStringUntil('\n');
int s2f = str.toFloat();
if (s2f < 0) {
if (s2f < -50){
analogWrite(lf, 20);
analogWrite(rf, 130-s2f);
analogWrite(lb, 0);
analogWrite(rb, 0);
}
else {
analogWrite(lf, 50);
analogWrite(rf, 50-s2f);
analogWrite(lb, 0);
analogWrite(rb, 0);
}
}
else if (s2f > 0) {
if (s2f > 50){
analogWrite(lf, 130+s2f);
analogWrite(rf, 40);
analogWrite(lb, 0);
analogWrite(rb, 0);
}
else {
analogWrite(lf, 50+s2f);
analogWrite(rf, 50);
analogWrite(lb, 0);
analogWrite(rb, 0);
}
}
}
}