-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnov4_testmotors.ino
103 lines (73 loc) · 2.12 KB
/
nov4_testmotors.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
const int M1_dir1 = 50;
const int M1_dir2 = 52;
const int pwm1= 2;
const int M2_dir1 = 40;
const int M2_dir2 = 42;
const int pwm2= 4;
char c;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
// make the pins outputs:
pinMode(M1_dir1, OUTPUT);
pinMode(M1_dir2, OUTPUT);
pinMode(pwm1, OUTPUT);
pinMode(M2_dir1, OUTPUT);
pinMode(M2_dir2, OUTPUT);
pinMode(pwm2, OUTPUT);
pinMode(48, OUTPUT);
}
void loop()
{
// put your main code here, to run repeatedly:
while (Serial.available() > 0) //while user gives input
{
c = Serial.read(); //read user input
if (c == 'f') s
{
digitalWrite(M1_dir1, HIGH);
digitalWrite(M1_dir2, LOW);
digitalWrite(48, HIGH);
analogWrite(pwm1, 70);
}
else if(c == 'b')
{
digitalWrite(M1_dir1, LOW);
digitalWrite(M1_dir2, HIGH);
digitalWrite(48, HIGH);
analogWrite(pwm1, 100);
}
else if(c == 's')
{
digitalWrite(M1_dir1, LOW);
digitalWrite(M1_dir2, LOW);
digitalWrite(48, HIGH);
analogWrite(pwm1, 0);
}
else if (c == 'q')
{
digitalWrite(M2_dir1, HIGH);
digitalWrite(M2_dir2, LOW);
digitalWrite(44, HIGH);
analogWrite(pwm2, 70);
}
else if(c == 'w')
{
digitalWrite(M2_dir1, LOW);
digitalWrite(M2_dir2, HIGH);
digitalWrite(44, HIGH);
analogWrite(pwm2, 100);
}
else if(c == 'e')
{
digitalWrite(M2_dir1, LOW);
digitalWrite(M2_dir2, LOW);
digitalWrite(44, HIGH);
analogWrite(pwm2, 0);
}
}
// digitalWrite(M1_dir1, HIGH);
// digitalWrite(M1_dir2, LOW);
// digitalWrite(48, HIGH);
// analogWrite(pwm1, 150);
}