CCCPaste

Motor Control rev_01

/********* 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: Motor Control
	- Source Code compiled for: Arduino Mega
	- Source Code created on: 2024-03-14 07:10:25

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

/****** SYSTEM REQUIREMENTS *****/
/****** SYSTEM REQUIREMENT 1 *****/
	/* make an Arduino troubleshooting program for motor */
	/* pins 8 and 9  by using encoder pins 17 and 367 */
/****** END SYSTEM REQUIREMENTS *****/

/****** DEFINITION OF LIBRARIES *****/
#include 	//https://github.com/ArminJo/PWMMotorControl

/****** FUNCTION PROTOTYPES *****/
void setup(void);
void loop(void);

/***** DEFINITION OF DIGITAL INPUT PINS *****/
const uint8_t encoder_PIN_D2 = 2;

/****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
CarPWMMotorControl motorControl; // Instantiate the CarPWMMotorControl object

// Define motor control pin numbers
const uint8_t RIGHT_MOTOR_FORWARD_PIN = 3;
const uint8_t RIGHT_MOTOR_BACKWARD_PIN = 4;
const uint8_t RIGHT_MOTOR_PWM_PIN = 5;
const uint8_t RIGHT_MOTOR_INTERRUPT = 0;

void setup(void) {
  // put your setup code here, to run once:
  pinMode(encoder_PIN_D2, INPUT);

  // Initialize the motor control object
  motorControl.init(RIGHT_MOTOR_FORWARD_PIN, RIGHT_MOTOR_BACKWARD_PIN, RIGHT_MOTOR_PWM_PIN, RIGHT_MOTOR_INTERRUPT, STOP_MODE_BRAKE, STOP_MODE_RELEASE);
}

void loop(void) {
  // put your main code here, to run repeatedly:

  // Example usage of the motor control object

  // Set the drive speed to maximum forward
  motorControl.setDriveSpeedPWM(255);

  // Delay for 2 seconds
  delay(2000);

  // Set the drive speed to maximum backward
  motorControl.setDriveSpeedPWM(-255);

  // Delay for 2 seconds
  delay(2000);

  // Stop the motor
  motorControl.stop();

  // Delay for 2 seconds
  delay(2000);
}