Adafruit Library
seesaw_motor.h
1 #ifndef _SEESAW_MOTOR_H
2 #define _SEESAW_MOTOR_H
3 
4 #include "Adafruit_seesaw.h"
5 
6 /**************************************************************************/
10 /**************************************************************************/
11 class seesaw_Motor {
12 public:
13  /**************************************************************************/
18  /**************************************************************************/
20  _ss = ss;
21  _pina = -1;
22  _pinb = -1;
23  _throttle = 0;
24  }
25 
26  ~seesaw_Motor() {}
27 
28  /**************************************************************************/
34  /**************************************************************************/
35  void attach(int pina, int pinb) {
36  _pina = pina;
37  _pinb = pinb;
38  }
39 
40  /**************************************************************************/
46  /**************************************************************************/
47  void throttle(float value) {
48  if (_pina < 0 || _pinb < 0)
49  return;
50 
51  value = constrain(value, -1.0, 1.0);
52  _throttle = value;
53  uint16_t absolute = fabs(value) * 65535;
54 
55  if (value > 0) {
56  _ss->analogWrite(_pina, 0);
57  _ss->analogWrite(_pinb, absolute);
58  } else if (value < 0) {
59  _ss->analogWrite(_pina, absolute);
60  _ss->analogWrite(_pinb, 0);
61  } else {
62  // both are off
63  _ss->analogWrite(_pina, 0);
64  _ss->analogWrite(_pinb, 0);
65  }
66  }
67 
68  /**************************************************************************/
73  /**************************************************************************/
74  float getThrottle() { return _throttle; }
75 
76 private:
77  Adafruit_seesaw *_ss;
78  int8_t _pina, _pinb;
79  float _throttle;
80 };
81 
82 #endif
void throttle(float value)
set the throttle
Definition: seesaw_motor.h:47
Class that stores state and functions for seesaw motor interface.
Definition: seesaw_motor.h:11
Class that stores state and functions for interacting with seesaw helper IC.
Definition: Adafruit_seesaw.h:235
void attach(int pina, int pinb)
attach the motor to the specified PWM pins
Definition: seesaw_motor.h:35
float getThrottle()
get the current throttle value
Definition: seesaw_motor.h:74
virtual void analogWrite(uint8_t pin, uint16_t value, uint8_t width=8)
write a PWM value to a PWM-enabled pin
Definition: Adafruit_seesaw.cpp:509
seesaw_Motor(Adafruit_seesaw *ss)
class constructor
Definition: seesaw_motor.h:19