/* 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 using PWM from 50 to 250 on both directions: ClockWise rotation, stops * for 0.5 secs; then CounterClockWise rotation, stops for 0.5secs. * * 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; 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 for (speed=50; speed<=250; speed++){ analogWrite(motorPin1, speed); analogWrite(motorPin2, 0); delay(50);} analogWrite(motorPin1, 0); analogWrite(motorPin2, 0); delay(500); for (speed=50; speed<=250; speed++){ analogWrite(motorPin2, speed); analogWrite(motorPin1, 0); delay(50);} analogWrite(motorPin1, 0); analogWrite(motorPin2, 0); delay(500); }