-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdrive_with_random_works.ino
75 lines (56 loc) · 1.28 KB
/
drive_with_random_works.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
//int switchPinBlack = 5; //black button
int y=4; //variable set to neutral value
int x=4;
int z=4;
#include <Shieldbot.h>
Shieldbot shieldbot = Shieldbot();
void setup() {
Serial.begin(9600);
//pinMode (switchPinBlack, INPUT); // black button
digitalWrite (2, HIGH);// run voltage through black button
attachInterrupt( 0, blackpush, FALLING); // when black button is pressed, interrupt
digitalWrite (3, HIGH);
attachInterrupt( 1, redpush, FALLING);
shieldbot.setMaxSpeed(225);
Serial.println("setup");
randomSeed(analogRead(0));
}
void loop() {
// while (y==4){ // may be redundant
// delay (1000);
z= random (1,3);
if (y==9){ //If black button is pressed, drive one wheel
if (z==1){
shieldbot.drive(50,0);
}
else if (z==2) {
shieldbot.drive(0,50);
}
delay(500);
y = 4;
x = 4;
}
else if (y==4){
shieldbot.drive(0,0);
}
else if (y==6){ //If black button is pressed, drive one wheel
if (z==1){
shieldbot.drive(50,0);
}
else if (z==2) {
shieldbot.drive(0,50);
}
delay(500);
y = 4;
x = 4;
}
else {
shieldbot.drive(0,0);
}
}
void blackpush(){
y= 9;
}
void redpush(){
y= 6;
}