-
Notifications
You must be signed in to change notification settings - Fork 0
/
Arduino code.ino
70 lines (60 loc) · 1.34 KB
/
Arduino code.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
//L293D
//Motor A
const int motorPin1 = 5;
const int motorPin2 = 6;
//Motor B
const int motorPin3 = 9;
const int motorPin4 = 10 ;
char serialData;
void setup(){
pinMode(motorPin1, OUTPUT);
pinMode(motorPin2, OUTPUT);
pinMode(motorPin3, OUTPUT);
pinMode(motorPin4, OUTPUT);
Serial.begin(9600);
}
void loop(){
serialData=Serial.read();
if(serialData=='w')
{
analogWrite(motorPin1,255);
analogWrite(motorPin2,0);
analogWrite(motorPin3,255);
analogWrite(motorPin4,0);
}
if(serialData=='a')
{
analogWrite(motorPin1,170);
analogWrite(motorPin2,0);
analogWrite(motorPin3,255);
analogWrite(motorPin4,0)
}
if(serialData=='d')
{
analogWrite(motorPin1,255);
analogWrite(motorPin2,0);
analogWrite(motorPin3,170);
analogWrite(motorPin4,0)
}
if(serialData=='s')
{
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, LOW);
digitalWrite(motorPin3, LOW);
digitalWrite(motorPin4, LOW);
}
if(serialData=='c')
{
analogWrite(motorPin1,255);
analogWrite(motorPin2,0);
analogWrite(motorPin3,0);
analogWrite(motorPin4,0)
}
if(serialData=='z')
{
analogWrite(motorPin1,0);
analogWrite(motorPin2,0);
analogWrite(motorPin3,255);
analogWrite(motorPin4,0)
}
}