This repository was archived by the owner on Dec 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMegaMotoBase.cpp
More file actions
143 lines (133 loc) · 3.92 KB
/
Copy pathMegaMotoBase.cpp
File metadata and controls
143 lines (133 loc) · 3.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/********************************************//**
* \file MegaMotoBase.cpp
* \author Alexander Hogen
* \date 1/11/2017
* \version 0.1
* \brief Contains the definitions for all the
* member methods of the MegaMotoBase class.
*
* Released into the public domain.
*
***********************************************/
#include "MegaMotoBase.h"
/********************************************//**
* \brief Constructor to initialize with pin
* numbers for PWM A and PWM B and
* specify the motor wiring.
*
* All data members initialized to their empty
* or default values. The name of the multiplier
* is set to the string passed in as the first
* argument. The multiplier bit width is set
* to the value of the second argument.
*
* \param pin_pwm_a is a byte. Specify the pin
* used for MegaMoto PWM A here.
*
* \param pin_pwm_b is a byte. Specify the pin
* used for MegaMoto PWM B here.
*
***********************************************/
MegaMotoBase::MegaMotoBase(
unsigned char pin_pwm_a,
unsigned char pin_pwm_b)
: use_enable_pin( false ),
pin_en( 255 ),
pin_a ( pin_pwm_a ),
pin_b ( pin_pwm_b ),
pwm_step_delay_ms (3)
{
// Set pins to output mode for MegaMoto
pinMode(pin_a, OUTPUT);
pinMode(pin_b, OUTPUT);
// Turn OFF both A and B PWM outputs
analogWrite(pin_a, 0);
analogWrite(pin_b, 0);
}
/********************************************//**
* \brief Constructor to initialize with pin
* numbers for PWM A, PWM B, and Enable.
* Also specify the motor wiring.
*
* All data members initialized to their empty
* or default values. The name of the multiplier
* is set to the string passed in as the first
* argument. The multiplier bit width is set
* to the value of the second argument.
*
* \param pin_pwm_a is a byte. Specify the pin
* used for MegaMoto PWM A here.
*
* \param pin_pwm_b is a byte. Specify the pin
* used for MegaMoto PWM B here.
*
* \param pin_enable is a byte. Specify the pin
* used for the MegaMoto Enable pin here.
*
***********************************************/
MegaMotoBase::MegaMotoBase(
unsigned char pin_pwm_a,
unsigned char pin_pwm_b,
unsigned char pin_enable )
: use_enable_pin( true ),
pin_en( pin_enable ),
pin_a ( pin_pwm_a ),
pin_b ( pin_pwm_b ),
pwm_step_delay_ms (3)
{
// Set pins to output mode for MegaMoto
pinMode(pin_a, OUTPUT);
pinMode(pin_b, OUTPUT);
pinMode(pin_en, OUTPUT);
// Turn OFF both A and B PWM outputs
analogWrite(pin_a, 0);
analogWrite(pin_b, 0);
// Enable the MegaMoto
digitalWrite(pin_en, HIGH);
}
/********************************************//**
* \brief Setter to change the ms delay when
* stepping up or down the PWM duty cycle.
*
* Provide the new delay time in milliseconds to
* this method if you want to change the delay
* time when "fading/feathering/sliding/ramping"
* the PWM duty cycle up or down.
*
* \param new_ms_delay is an int
***********************************************/
void MegaMotoBase::SetStepDelay( int new_ms_delay )
{
pwm_step_delay_ms = new_ms_delay;
}
/********************************************//**
* \brief Getter which returns the current delay
* used when changing the PWM duty cycle.
*
* Returns the delay time in milliseconds used
* when "fading/feathering/sliding/ramping" the
* PWM duty cycle up or down.
*
* \return integer value of pwm_step_delay_ms
*
***********************************************/
int MegaMotoBase::GetStepDelay() const
{
return( pwm_step_delay_ms );
}
/********************************************//**
* \brief Enable the MegaMoto controller
*
* Used when the Enable pin is being controlled
* to enable the MegaMoto controller. If you have
* called Disable(), you will probably need to call
* this function again.
*
***********************************************/
void MegaMotoBase::Enable()
{
if(use_enable_pin)
{
digitalWrite(pin_en, HIGH);
}
}