0% found this document useful (0 votes)
29 views2 pages

DC Motor C++ Coding

The document defines a header file for a Motor class in Arduino, which includes methods for controlling motor direction and speed. It contains private member variables for motor pins and speed, and public methods for initializing the motor and controlling its operation. The use of include guards prevents duplicate inclusion of the header file.

Uploaded by

sk.ngeno42
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views2 pages

DC Motor C++ Coding

The document defines a header file for a Motor class in Arduino, which includes methods for controlling motor direction and speed. It contains private member variables for motor pins and speed, and public methods for initializing the motor and controlling its operation. The use of include guards prevents duplicate inclusion of the header file.

Uploaded by

sk.ngeno42
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

#ifndef MOTORS_H // Include guard to prevent duplicate inclusion

#define MOTORS_H

#include <Arduino.h> // For Arduino-specific functions (e.g., digitalWrite)

class Motor {

private:

int pin1; // Motor control pin 1 (e.g., IN1 on L298N)

int pin2; // Motor control pin 2 (e.g., IN2 on L298N)

int pwmPin; // PWM pin for speed control (e.g., ENA on L298N)

int speed; // Current speed (0-255)

public:

// Constructor: Initialize motor pins

Motor(int pin1, int pin2, int pwmPin);

// Set up motor pins (call in setup())

void begin();

// Control motor direction and speed

void forward(int speed = 255);

void reverse(int speed = 255);

void stop();

void brake(); // Short brake (stops motor instantly)

};
#endif // MOTOR_H

You might also like