1
2
3
4int val;
5int IN4 = 11;
6int IN3 = 10;
7int IN2 = 9;
8int IN1 = 8;
9int LED = 13;
10
11void setup()
12{
13 Serial.begin(9600);
14 pinMode (IN4, OUTPUT);
15 pinMode (IN3, OUTPUT);
16 pinMode (IN2, OUTPUT);
17 pinMode (IN1, OUTPUT);
18 pinMode (LED, OUTPUT);
19}
20
21void loop()
22{
23if (Serial.available())
24 {
25 val = Serial.read();
26 if (val == 'U')
27 {
28 digitalWrite (IN1, HIGH);
29 digitalWrite (IN2, LOW);
30 digitalWrite (IN3, HIGH);
31 digitalWrite (IN4, LOW);
32 }
33 if (val == 'D')
34 {
35 digitalWrite (IN1, LOW);
36 digitalWrite (IN2, HIGH);
37 digitalWrite (IN3, LOW);
38 digitalWrite (IN4, HIGH);
39 }
40 if (val == 'A')
41 {
42 digitalWrite (IN1, HIGH);
43 digitalWrite (IN2, LOW);
44 digitalWrite (IN3, HIGH);
45 digitalWrite (IN4, LOW);
46 }
47 if ( val == 'B')
48 {
49 digitalWrite (IN1, LOW);
50 digitalWrite (IN2, HIGH);
51 digitalWrite (IN3, LOW);
52 digitalWrite (IN4, HIGH);
53 }
54 if ( val == 'R')
55 {
56 digitalWrite (IN1, LOW);
57 digitalWrite (IN2, HIGH);
58 digitalWrite (IN3, HIGH);
59 digitalWrite (IN4, LOW);
60 }
61 if ( val == 'L')
62 {
63 digitalWrite (IN1, HIGH);
64 digitalWrite (IN2, LOW);
65 digitalWrite (IN3, LOW);
66 digitalWrite (IN4, HIGH);
67 }
68 if ( val == 'X')
69 {
70 digitalWrite (LED, HIGH);
71 }
72 if ( val == 'Y')
73 {
74 digitalWrite (LED, LOW);
75 }
76 if ( val == 'S')
77 {
78 stop();
79 }
80 }
81}
82
83void stop()
84 {
85 digitalWrite (IN1, LOW);
86 digitalWrite (IN2, LOW);
87 digitalWrite (IN3, LOW);
88 digitalWrite (IN4, LOW);
89 }