JMotor
Loading...
Searching...
No Matches
JMotorDriverAvrPWM.h
Go to the documentation of this file.
1#ifndef J_MOTOR_DRIVER_AVR_PWM_H
2#define J_MOTOR_DRIVER_AVR_PWM_H
3#include "JMotorDriver.h"
4#include <Arduino.h>
5
11private:
12 bool enabled = false;
13 byte pin;
14
15public:
19 int PWM_RANGE = 255;
20 bool disableState = LOW;
27 JMotorDriverAvrPWM(byte _pin, bool _disableState = LOW)
28 {
29 enabled = false;
30 pin = _pin;
31 _disableState = disableState;
32 }
33 bool set(float _val)
34 {
35 if (enabled) {
36 int val = constrain(_val * PWM_RANGE, 0, PWM_RANGE);
37 analogWrite(pin, val);
38 }
39 return (_val > 0.0) && (_val < 1.0);
40 }
41 bool setEnable(bool _enable)
42 {
43 if (_enable) {
44 if (!enabled) {
45 // actually enable
46 enabled = true;
47 analogWrite(pin, !disableState ? 0 : PWM_RANGE);
48 return true;
49 }
50 } else { // disable
51 if (enabled) {
52 // actually disable
53 enabled = false;
54 analogWrite(pin, !disableState ? 0 : PWM_RANGE);
55 return true;
56 }
57 }
58 return false;
59 }
60 bool getEnable()
61 {
62 return enabled;
63 }
65 {
66 return 1.0;
67 }
69 {
70 return 0.0;
71 }
72};
73
74#endif
wrapper for analogWrite()
Definition JMotorDriverAvrPWM.h:10
int PWM_RANGE
change PWM_RANGE to match the range of analogWrite (change after using analogWriteResolution)
Definition JMotorDriverAvrPWM.h:19
float getMaxRange()
high end of the range
Definition JMotorDriverAvrPWM.h:64
bool disableState
Definition JMotorDriverAvrPWM.h:20
bool setEnable(bool _enable)
use to enable or disable a motor, and sets up pin states
Definition JMotorDriverAvrPWM.h:41
bool set(float _val)
set motor power
Definition JMotorDriverAvrPWM.h:33
float getMinRange()
low end of the range
Definition JMotorDriverAvrPWM.h:68
JMotorDriverAvrPWM(byte _pin, bool _disableState=LOW)
constructor, sets pins
Definition JMotorDriverAvrPWM.h:27
bool getEnable()
get the enable state of the driver
Definition JMotorDriverAvrPWM.h:60
defines common interface for all types of JMotorDrivers
Definition JMotorDriver.h:10