19 template <
size_t SmoothLevel>
32 SmoothlyMotor2(
const uint8_t pinA,
const uint8_t pinP)
42 pinMode(pinA, OUTPUT);
47 void move(
const int16_t power)
49 const int16_t p = movingAverage(constrain(power, -250, 250));
50 digitalWrite(pinA, p >= 0 ? HIGH : LOW);
51 analogWrite(pinP, abs(p));
63 Serial.print(movingAverage.
getValue());
70 template <
size_t SmoothLevel>
85 SmoothlyMotor3(
const uint8_t pinA,
const uint8_t pinB,
const uint8_t pinP)
96 pinMode(pinA, OUTPUT);
97 pinMode(pinB, OUTPUT);
102 void move(
const int16_t power)
104 movingAverage.
update(constrain(power, -250, 250));
105 const int16_t p = movingAverage.
getValue();
106 digitalWrite(pinA, p >= 0 ? HIGH : LOW);
107 digitalWrite(pinB, p <= 0 ? HIGH : LOW);
108 analogWrite(pinP, abs(p));
120 Serial.print(movingAverage.
getValue());
125 using Motor2 = SmoothlyMotor2<50>;
126 using Motor3 = SmoothlyMotor3<50>;
128#ifdef __AVR_ATmega328P__
131 inline void ChangePwmPeriod()
移動平均クラス
Definition MovingAverage.hpp:17
double getValue() const noexcept
平均値の取得
Definition MovingAverage.hpp:49
void update(int value) noexcept
値の更新
Definition MovingAverage.hpp:37