ESP_IOT v2.5
IOT ESP Coding
DCMotorStepperClass.cpp
Go to the documentation of this file.
1//! \link DCMotorStepper
2// DCMotorStepper.cpp
3//
4//
5// Created by Scott Moody on 3/16/25.
6//
7
9
10// from Dispense it calls getFeederType_mainModule()
11#include "StepperModule.h"
12
13//#include "TimerDelayClass.h"
14//! create instance of the timer class
16
17//! default .. this could be set via Preferences (TODO)
19
20
21/******************stepper declarations******************************/
22
24{
25 SerialDebug.printf("DCMotorStepperClass init %s\n", config);
27
28}
29
30
31//! from Orion's small program 3.16.25
32#define MOTOR_IN1 13
33#define MOTOR_IN2 12
34#define BUZZER_IN1 14
35#define BUZZER_IN2 27
36
37#define NUM_PINS 2
38////Put all the pins in an array to make them easy to work with
40 MOTOR_IN1, //IN1 on the ULN2003 Board, BLUE end of the Blue/Yellow motor coil
41 MOTOR_IN2 //IN2 on the ULN2003 Board, PINK end of the Pink/Orange motor coil
42};
43/**
44 This replaces the following, when clearPins() called
45
46 pinMode(MOTOR_IN1, OUTPUT);
47 pinMode(MOTOR_IN2, OUTPUT);
48 pinMode(BUZZER_IN1, OUTPUT);
49 pinMode(BUZZER_IN2, OUTPUT);
50 digitalWrite(MOTOR_IN1, LOW);
51 digitalWrite(MOTOR_IN2, LOW);
52 digitalWrite(BUZZER_IN1, LOW);
53 digitalWrite(BUZZER_IN2, LOW);
54 #endif
55 */
56
57/************* Set all motor pins off which turns off the motor ************************************************/
59{
60 for (int pin = 0; pin < NUM_PINS; pin++)
61 {
62 pinMode(_pins_DCMotorStepperClass[pin], OUTPUT);
63 digitalWrite(_pins_DCMotorStepperClass[pin], LOW);
64 }
65}
66
67//! These are called from StepperModule
68//Prepare motor controller
70{
71 clearPins_DCMotorStepper(); // Go turn all motor pins off
72
73 //! 3.26.25 put buzzer code here for now..
74 pinMode(BUZZER_IN1, OUTPUT);
75 pinMode(BUZZER_IN2, OUTPUT);
76 digitalWrite(BUZZER_IN1, LOW);
77 digitalWrite(BUZZER_IN2, LOW);
78}
79
80
81//! stop the motor
83{
84 Serial.println("DCMotorStepper: STOP");
85
86 //!stops motor
88
89 //!user timer class instance
91}
92
93//!This will advance the stepper clockwise once by the angle specified in SetupStepper. Example 16 pockets in UNO is 22.5 degrees
95{
96 SerialDebug.println("**************** DCMotorStepper::Starting DCMotorStepper *******************");
97
98#define NEW_CODE_HERE
99 //Set the four pins to their proper state for the current step in the sequence,
100 //and for the current direction
101
102 if (this->isClockwiseDirection()) {
103 digitalWrite(MOTOR_IN1, LOW);
104 digitalWrite(MOTOR_IN2, HIGH);
105 } else {
106 digitalWrite(MOTOR_IN1, HIGH);
107 digitalWrite(MOTOR_IN2, LOW);
108 }
109
110 //! grab this value.
112
113
114 //! start the delay.. (which at .5 might not be needed...)
116
117#define BUZZER_CODE
118 //! 3.26.25 put buzzer code here for now ..
120 if (buzzerEnabled)
121 {
122 digitalWrite(BUZZER_IN1, HIGH);
123 digitalWrite(BUZZER_IN2, LOW);
124 delay(500);
125 digitalWrite(BUZZER_IN1, LOW);
126 digitalWrite(BUZZER_IN2, LOW);
127 }
128
129 SerialDebug.println("**************** DCMotorStepper::Ending DCMotorStepper *************");
130
131}
132
133
134//!loop the PTStepper (so timer can run)
136{
137 //!user timer class instance
139 {
140 this->stop_MotorStepper();
141 }
142}
void clearPins_DCMotorStepper()
#define MOTOR_IN2
float _delaySeconds_DCMotorStepper_setting
default .. this could be set via Preferences (TODO)
#define NUM_PINS
TimerDelayClass * _timerDelayClass_DCMotorStepperClass
DCMotorStepper
#define BUZZER_IN1
#define MOTOR_IN1
from Orion's small program 3.16.25
int _pins_DCMotorStepperClass[NUM_PINS]
#define BUZZER_IN2
float getPreferenceFloat_mainModule(int preferenceID)
called to set a preference (which will be an identifier and a string, which can be converted to a num...
boolean getPreferenceBoolean_mainModule(int preferenceID)
called to set a preference (which will be an identifier and a string, which can be converted to a num...
#define PREFERENCE_STEPPER_BUZZER_VALUE
stepper preferences
#define PREFERENCE_STEPPER_ANGLE_FLOAT_SETTING
void loop_MotorStepper()
setup the PTStepper
void start_MotorStepper()
starts the PTStepper
DCMotorStepperClass(char *config)
constructor
void setup_MotorStepper()
setup the PTStepper
void stop_MotorStepper()
stops motor
An mostly virtual class.
boolean isClockwiseDirection()
returns if clockwise
An concrete class.
void startDelay(float delayAmountSeconds)
starts delay calculation
boolean delayFinished()
whether the currently delay is finished, false if not running at all
void stopDelay()
stops delay