SkillAgentSearch skills...

InterruptHandler

Object-oriented interrupt handler library for Arduino

Install / Use

/learn @zeitgeist87/InterruptHandler
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

InterruptHandler

An object-oriented interrupt handler library for the Arduino. Instead of the simple C function pointer used by the built-in attachInterrupt() function, it uses a pure C++ virtual method as a callback. This allows for a cleaner more object oriented design, which is especially useful for libraries. The performance should be on par with the built-in version of attachInterrupt(), because it is based on an only slightly modified version of the original Arduino source code.

Usage

The usage is very simple. You just inherit from the class InterruptHandler and implement the method handleInterrupt().

#include <InterruptHandler.h>

// Inherit from InterruptHandler
class MyLib : InterruptHandler {
  byte inputPin;
  unsigned long localState1;
  unsigned long localState2;

public:
  MyLib(byte inputPin) : inputPin(pin) {}
  
  void begin() {
    pinMode(inputPin, INPUT);
    attachInterrupt(digitalPinToInterrupt(inputPin), CHANGE);
  }

  void stop() {
    detachInterrupt(digitalPinToInterrupt(inputPin));
  }

  // Overwrite handleInterrupt() method
  virtual void handleInterrupt(int8_t interruptNum) {
    // Do something
    localState1 = digitalRead(inputPin);
    // ...
  }
};
View on GitHub
GitHub Stars8
CategoryDevelopment
Updated2y ago
Forks3

Languages

C++

Security Score

70/100

Audited on Oct 30, 2023

No findings