SkillAgentSearch skills...

PinChangeInterruptHandler

An object-oriented pin-change interrupt handler library for the Arduino

Install / Use

/learn @zeitgeist87/PinChangeInterruptHandler
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

PinChangeInterruptHandler

An object-oriented pin-change interrupt handler library for the Arduino. It uses a pure C++ virtual method as a callback. This allows for a clean and object oriented design, which is especially useful for libraries. The code is heavily influenced by the excellent PinChangeInterrupt library of NicoHood.

Usage

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

#include <PinChangeInterruptHandler.h>

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

public:
  MyLib(byte inputPin) : inputPin(pin) {}
  
  void begin() {
    pinMode(inputPin, INPUT);
    attachPCInterrupt(digitalPinToPCINT(inputPin));
  }

  void stop() {
    detachPCInterrupt(digitalPinToPCINT(inputPin));
  }

  // Overwrite handlePCInterrupt() method
  virtual void handlePCInterrupt(int8_t interruptNum, bool value) {
    // Do something
    localState1 = value;
    // ...
  }
};

Related Skills

View on GitHub
GitHub Stars10
CategoryDevelopment
Updated1y ago
Forks7

Languages

C++

Security Score

75/100

Audited on Jul 17, 2024

No findings