CCCPaste

Dual Motor Control rev_04

/********* Pleasedontcode.com **********

	Pleasedontcode thanks you for automatic code generation! Enjoy your code!

	- Terms and Conditions:
	You have a non-exclusive, revocable, worldwide, royalty-free license
	for personal and commercial use. Attribution is optional; modifications
	are allowed, but you're responsible for code maintenance. We're not
	liable for any loss or damage. For full terms,
	please visit pleasedontcode.com/termsandconditions.

	- Project: Dual Motor Control
	- Source Code NOT compiled for: ESP32 DevKit V1
	- Source Code created on: 2024-05-19 00:29:01

********* Pleasedontcode.com **********/

/****** SYSTEM REQUIREMENTS *****/
/****** SYSTEM REQUIREMENT 1 *****/
	/* Ensure the motors are controlled individually: Set */
	/* speed, direction, and movement for each motor */
	/* independently using L298NX2 library functions. */
/****** SYSTEM REQUIREMENT 2 *****/
	/* Ensure precise control of L298N motor drivers: Set */
	/* speed and direction independently for each motor */
	/* using L298NX2 library functions. */
/****** END SYSTEM REQUIREMENTS *****/

/****** DEFINITION OF LIBRARIES *****/
#include  // Include the L298NX2 library
#include  // Include the ConfigAssist library

/****** FUNCTION PROTOTYPES *****/
void setup(void);
void loop(void);
void updateOutputs(); // Add function prototype for updateOutputs

/***** DEFINITION OF PWM OUTPUT PINS *****/
const uint8_t EN_A = 4; // Define the PWM pin for motor A
const uint8_t EN_B = 16; // Define the PWM pin for motor B

/****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
L298NX2 motors(EN_A, 5, 6, EN_B, 7, 8); // Initialize L298NX2 object with pins for motor A and B
ConfigAssist conf; // Initialize ConfigAssist object

void setup(void)
{
  // put your setup code here, to run once:
  pinMode(EN_A, OUTPUT); // Set EN_A pin as output
  pinMode(EN_B, OUTPUT); // Set EN_B pin as output

  // Initialize ConfigAssist with INI file and configuration dictionary
  conf.init(INI_FILE, appConfigDict_json);

  // Ensure the motors are controlled individually
  // Set speed, direction, and movement for each motor independently
  motors.setSpeedA(120);
  motors.setSpeedB(80);
}

void loop(void)
{
  // put your main code here, to run repeatedly:
  updateOutputs(); // Refresh output data
}

void updateOutputs()
{
  // Ensure precise control of L298N motor drivers
  // Set speed and direction independently for each motor
  motors.runForA(3000, L298N::FORWARD);
  motors.runForB(3000, L298N::BACKWARD);
}