/\* \* Bidirectional Motor Control with standalone L293 \* \* Example of using L293 library to control one or more DC Birirectional Motors with the standalone configuration of the L293 \* \* Created by Giuseppe Masino, 25 may 2016 \* Author URL http://www.facebook.com/dev.giuseppemasino \* \* This work is licensed under the Creative Commons Attribution-ShareAlike 4.0 International License. \* To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/4.0/. \* ----------------------------------------------------------------------------------- \* \* Things that you need: \* - Arduino\Genuino MEGA2560 \* (any Arduino\Genuino board can be used, the important is that the L293 pin 1 is connected to a PWM-enabled pin of Arduino) \* (on the Arduino MEGA2560 all pins from 2 to 13 are PWM-enabled) \* (use of pin 13 is discouraged because it can cause issues when the board resets) \* \* - L293 \* - A DC Birirectional Motor (max 5V-4mA) \* \* ----------------------------------------------------------------------------- \* \* The circuit ( standalone version ): \* - Arduino pin 2 -> L293 pin 1 \* - Arduino pin 3 -> L293 pin 2 \* - Arduino pin 4 -> L293 pin 7 \* - Arduino GND -> L293 pin 4, 5 \* - Arduino 5V -> L293 pin 16, 8 \* \* - L293 pin 3 -> a terminal of the motor \* - L293 pin 6 -> the other terminal of the motor \* \* The circuit ( twoWire version ): \* https://github.com/qub1750ul/Arduino\_L293/blob/master/extras/L293\_twoWire.svg \* \*/
// by default this example uses the standalone version of the library // comment out the following row to switch to the twoWire version #define use\_standalone
// import the library in the sketch #include <L293.h>
// give a name to the pins that we use const int IN1 = 2; // that is the pin that we use to control the motor's speed const int IN2 = 3; // this is the pin that we use to tell the motor to go forward const int EN1 = 4; // this is the pin that we use to tell the motor to go reverse
const int IN3 = 6; // that is the pin that we use to control the motor's speed const int IN4 = 7; // this is the pin that we use to tell the motor to go forward const int EN2 = 5; // this is the pin that we use to tell the motor to go reverse
void loop() { motor1.forward( 255 ); // set the direction and the speed of the motor motor2.forward( 255 ); // set the direction and the speed of the motor delay( 1000 ); // wait for 1 second before doing else motor1.back( 255 ); // set a new direction and the speed of the motor motor2.back( 255 ); // set a new direction and the speed of the motor delay( 1000 ); // wait for 1 second before doing else motor1.stop(); // stop the motor motor2.stop(); // stop the motor delay( 1000 ); // wait for 1 second before doing else