/* Made by Jefferson Sandoval during the Output devices for the FabAcademy2021 * * This is just a simple testing code in Arduino for learning how to control a DC motor with * a L298N driver. * The code runs the motor: ClockWise for 2secs and turns it off for 0.2secs, then CounterClockWise * for 2secs and turns it off for 0.2secs. * * This code was uploaded to a board with an Attiny1614 microcontroller. Documentation: * http://fabacademy.org/2021/labs/kamplintfort/students/jefferson-sandoval/assignments/week13/ */ //Motor A const int motorPin1 = 0; const int motorPin2 = 1; const int Enable = 2; int speed = 200; void setup(){ //Set pins as outputs pinMode(motorPin1, OUTPUT); pinMode(motorPin2, OUTPUT); pinMode(Enable, OUTPUT); digitalWrite(Enable, 1); } void loop(){ //Control Motor A in both directions analogWrite(motorPin1, speed); analogWrite(motorPin2, 0); delay(2000); analogWrite(motorPin1, 0); analogWrite(motorPin2, 0); delay(200); analogWrite(motorPin2, speed); analogWrite(motorPin1, 0); delay(2000); analogWrite(motorPin1, 0); analogWrite(motorPin2, 0); delay(200); }