File tree 1 file changed +94
-0
lines changed
1 file changed +94
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include < SoftwareSerial.h>
2
+ #include < Shieldbot.h>
3
+
4
+ Shieldbot shieldbot = Shieldbot();
5
+ int polls[5 ];
6
+ int line;
7
+ int deliver=1 ;
8
+ boolean stopped=0 ;
9
+ byte postion=0 ;
10
+ byte lastDir=0 ;
11
+ void setup (){
12
+ Serial.begin (19200 );
13
+ pinMode (13 , OUTPUT);
14
+ digitalWrite (13 ,1 );
15
+ }
16
+
17
+ void loop (){
18
+ if (onLine ()){
19
+ if (onSquare ()){
20
+ shieldbot.drive (0 ,0 );
21
+ delay (1000 );
22
+ shieldbot.drive (100 ,100 );
23
+ postion+=1 ;
24
+ postion=postion%5 ;
25
+ if (postion==deliver){
26
+ digitalWrite (13 ,0 );
27
+ shieldbot.drive (40 ,40 );
28
+ delay (500 );
29
+ digitalWrite (13 ,1 );
30
+ }
31
+ }else if (!polls[2 ]){
32
+ shieldbot.forward ();
33
+ }else if (!polls[1 ]){
34
+ shieldbot.drive (80 ,0 );
35
+ lastDir=0 ;
36
+ }else if (!polls[3 ]){
37
+ shieldbot.drive (0 ,80 );
38
+ lastDir=1 ;
39
+ }else if (!polls[0 ]){
40
+ shieldbot.drive (50 ,0 );
41
+ lastDir=0 ;
42
+ }else if (!polls[4 ]){
43
+ shieldbot.drive (0 ,50 );
44
+ lastDir=1 ;
45
+ }
46
+
47
+ for (int i=0 ;i<5 ;i++){
48
+ Serial.print (polls[i]);
49
+ Serial.print (' ,' );
50
+ }
51
+ Serial.print (onLine ());
52
+ Serial.println (' ;' );
53
+ }
54
+ // If not on line, reverse towards last know direction
55
+ if (lastDir==0 ){
56
+ shieldbot.drive (0 ,-32 );
57
+ }
58
+ else {shieldbot.drive (-32 ,0 );}
59
+ }
60
+
61
+ boolean onLine (){
62
+ pollSensors ();
63
+ if (!polls[0 ]||!polls[1 ]||!polls[2 ]||!polls[3 ]||!polls[4 ]){
64
+ return true ;
65
+ }
66
+ else {return false ;}
67
+ }
68
+
69
+ boolean onSquare (){
70
+ pollSensors ();
71
+ if (!polls[0 ]&&!polls[1 ]&&!polls[2 ]&&!polls[3 ]&&!polls[4 ]){
72
+ return true ;
73
+ }
74
+ else {return false ;}
75
+ }
76
+
77
+ void pollSensors (){
78
+ polls[0 ]=shieldbot.readS1 ();
79
+ polls[1 ]=shieldbot.readS2 ();
80
+ polls[2 ]=shieldbot.readS3 ();
81
+ polls[3 ]=shieldbot.readS4 ();
82
+ polls[4 ]=shieldbot.readS5 ();
83
+ }
84
+
85
+ /*
86
+ int lineRead(int sensor){
87
+ readings[0]=analogRead(sensor);
88
+ digitalWrite(sensor, 1);
89
+ readings[1]=analogRead(sensor);
90
+ digitalWrite(sensor,0);
91
+ readings[2]=analogRead(sensor);
92
+ return(readings[1]-(readings[0]+readings[2])/2);
93
+ }
94
+ */
You can’t perform that action at this time.
0 commit comments