/* Project: L298N dual h-bridge motor driver module, 1 DC motor with speed control Function: DC motor rotates with minimum, medium,high speed and stops */ //************************************************************ int IN1 = 26;//input 1 of DC motor 1 attached to gpio 26 int IN2 = 27;//input 2 of DC motor 1 attached to gpio 27 int ENA = 14;//ENA of DC motor attached to gpio 14 //PWM properties const int freq = 30000; const int pwmChannel = 0; const int resolution = 8; int dutyCycle = 200; //************************************************************ void setup() { pinMode (ENA, OUTPUT); //sets ENA as OUTPUT pinMode (IN1, OUTPUT);//sets IN1 as OUTPUT pinMode (IN2, OUTPUT);//sets IN2 as OUTPUT //configure LED PWM functionalitites ledcSetup(pwmChannel, freq, resolution); //attach the channel to the GPIO to be controlled ledcAttachPin(ENA, pwmChannel); } void loop() { //DC motor is ready for turn digitalWrite (IN1, HIGH); digitalWrite (IN2, LOW); while (dutyCycle <= 255){ ledcWrite(pwmChannel, dutyCycle); dutyCycle = dutyCycle + 5; delay(500); } dutyCycle = 200; }