2 This program is free software: you can redistribute it and/or modify
3 it under the terms of the GNU Affero General Public License as
4 published by the Free Software Foundation, either version 3 of the
5 License, or (at your option) any later version.
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 GNU Affero General Public License for more details.
12 You should have received a copy of the GNU Affero General Public License
13 along with this program. If not, see <http://www.gnu.org/licenses/>.
16 // Pin 13 has an LED connected on most Arduino boards.
19 int motor1_enable
= 10;
22 int motor2_enable
= 3;
26 // the setup routine runs once when you press reset:
28 // initialize the digital pin as an output.
30 pinMode(motor1_enable
, OUTPUT
);
31 pinMode(motor1a
, OUTPUT
);
32 pinMode(motor1b
, OUTPUT
);
33 pinMode(motor2_enable
, OUTPUT
);
34 pinMode(motor2a
, OUTPUT
);
35 pinMode(motor2b
, OUTPUT
);
37 digitalWrite(led
, HIGH
);
38 digitalWrite(motor1_enable
, LOW
);
39 digitalWrite(motor1a
, LOW
);
40 digitalWrite(motor1b
, LOW
);
41 digitalWrite(motor2_enable
, LOW
);
42 digitalWrite(motor2a
, LOW
);
43 digitalWrite(motor2b
, LOW
);
46 void motorsRun(int left
, int right
, int ms_delay
) {
47 // Set left motor direction:
49 // Set left motor to go forward:
50 digitalWrite(motor1a
, HIGH
);
51 digitalWrite(motor1b
, LOW
);
53 // Set left motor to go backward:
54 digitalWrite(motor1a
, LOW
);
55 digitalWrite(motor1b
, HIGH
);
56 left
= -left
; // Make left a positive value:
59 analogWrite(motor2_enable
, left
); // Start motor in right direction
60 // Set left motor direction:
62 // Set right motor to go forward:
63 digitalWrite(motor2a
, HIGH
);
64 digitalWrite(motor2b
, LOW
);
66 // Set right motor to go backward:
67 digitalWrite(motor2a
, LOW
);
68 digitalWrite(motor2b
, HIGH
);
69 right
= -right
; // Make right a positive value:
71 analogWrite(motor1_enable
, left
); // Start motor in right direction
73 delay(ms_delay
); // Wait the specified amount of time
76 analogWrite(motor1_enable
, 0);
77 analogWrite(motor2_enable
, 0);
80 // the loop routine runs over and over again forever:
83 digitalWrite(led
, HIGH
); // turn the LED on (HIGH is the voltage level)
84 motorsRun(100, 100, 2000);// Run the robot forward
85 digitalWrite(led
, LOW
); // turn the LED off by making the voltage LOW
86 motorsRun(-100, -100, 2000); // Run the robot backward