Skip to content
This repository was archived by the owner on Jul 25, 2022. It is now read-only.

Commit a9ff04b

Browse files
committed
Added function to attach interrupts to digital pin.
Tested successfully!
1 parent 7c160dd commit a9ff04b

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

robot-control-src/DigitalPin.hpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
#include "GpioInterface.hpp"
55
#include <Arduino.h>
66

7-
template<std::uint8_t pin>
7+
template<std::uint8_t PIN>
88
class DigitalPin: public GpioInterface {
99
public:
10+
static constexpr std::uint8_t pin = PIN;
11+
1012
virtual int read() override
1113
{
1214
return readS();
@@ -33,4 +35,11 @@ class DigitalPin: public GpioInterface {
3335
}
3436
};
3537

38+
template<std::uint8_t PIN>
39+
void attachInterrupt(const DigitalPin<PIN>& gpio, void (* const interruptServiceRoutine)(void), const int mode)
40+
{
41+
attachInterrupt(digitalPinToInterrupt(gpio.pin), interruptServiceRoutine, mode);
42+
}
43+
44+
3645
#endif /* ROBOT_CONTROL_SRC_DIGITALPIN_HPP_ */

robot-control-src/GpioInterface.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class GpioInterface {
99
virtual int read() = 0;
1010
virtual void setMode(const std::uint8_t mode) = 0;
1111

12-
virtual ~GpioInterface() = 0;
12+
virtual ~GpioInterface() {};
1313
};
1414

1515
void digitalWrite(GpioInterface& gpio, const std::uint8_t value);

0 commit comments

Comments
 (0)