forked from stevenBowtie/ChairBot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChairBot_Basic.ino
More file actions
43 lines (39 loc) · 850 Bytes
/
Copy pathChairBot_Basic.ino
File metadata and controls
43 lines (39 loc) · 850 Bytes
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
#include <SoftwareSerial.h>
#include <NewPing.h>
#include <Wire.h>
#include <compass.h>
#include <ChairBot.h>
ChairBot cb;
boolean state=0;
int distance_threshold=50;
int right;
int left;
void setup() {
Serial.begin(9600);
cb.begin();
pinMode(13, OUTPUT);
}
void loop() {
// cb.turn(10);
left=cb.distance_left();
right=cb.distance_right();
if (left<distance_threshold && right<distance_threshold && left>0&&right>0){
cb.drive(-500,-500);
}
else if (left<distance_threshold && left>0){
cb.drive(250,-250);
delay(500);
}
else if (right<distance_threshold && right>0){
cb.drive(-250,250);
delay(500);
}
else{
cb.drive(500,500);
}
Serial.print(cb.distance_left());
Serial.print(",");
Serial.print(cb.distance_center());
Serial.print(",");
Serial.println(cb.distance_right());
}