Mutila: Mouse's Utilities for Arduino
Oft-used utilities: debouncing buttons, averaging samples, and so on.
SonicRanger.h
1 #pragma once
2 
3 #include <stdint.h>
4 
13 #ifdef ARDUINO_AVR_DIGISPARK
14 uint32_t pulseInLong(uint8_t pin, uint8_t state, uint32_t timeout);
15 #endif // ARDUINO_AVR_DIGISPARK
16 
17 class SonicRanger {
18 public:
19  static const uint16_t DefaultMaxRangeCm = 200;
20  static const uint8_t DefaultTimeoutMs = 15;
21 
22 public:
28  SonicRanger(const uint8_t trigPin, const uint8_t echoPin);
33  void begin();
51  uint16_t getRange();
52 
57  void setMaxRange(uint16_t cm) { _maxCm = cm; }
58 
68  void setTimeoutMs(uint16_t ms) { _timeoutMs = ms; }
69 
70 private:
71  const uint8_t _trigPin;
72  const uint8_t _echoPin;
73  uint16_t _maxCm;
74  uint16_t _timeoutMs;
75 
76 };
77 
void setMaxRange(uint16_t cm)
Definition: SonicRanger.h:57
uint16_t getRange()
Definition: SonicRanger.cpp:55
SonicRanger(const uint8_t trigPin, const uint8_t echoPin)
Definition: SonicRanger.cpp:41
void begin()
Definition: SonicRanger.cpp:49
void setTimeoutMs(uint16_t ms)
Definition: SonicRanger.h:68