Skip to content

An Arduino library for interfacing with things that output PWM signals.

Notifications You must be signed in to change notification settings

rawsonj/PWMInterrupt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 

Repository files navigation

PWMInterrupt

This is a library that implements a way to take as input a PWM signal into an arduino-compatible microcontroller and do stuff with it.

The original inspiration for this was to interface with an RC car receiver that would only output PWM signals of different widths to indicate button presses or toggles.

You only need to know the widths of the pulses you are looking for. Frequency of the signal is not required.

Everything is implemented in a call-back fashion and driven by interrupts to make it as efficient as possible.

Below is an example of how to use it in a sketch

#include "WProgram.h"
#include <PWMInterrupt.h>

#define OUTPUTPIN 13
#define PWMINPUT 2

void turn_off_output(void) {
    digitalWriteFast(OUTPUTPIN, LOW);
}

void turn_on_output(void) {
    digitalWriteFast(OUTPUTPIN, HIGH);
}

PWMInterrupt pwm_input(PWMINPUT, 1400, turn_off_output, turn_on_output, false);

void service(void) {
    pwm_input.service();
}

extern "C" int main(void)
{
    pinMode(OUTPUTPIN, OUTPUT);
    pinMode(PWMINPUT, INPUT);
    attachInterrupt(digitalPinToInterrupt(PWMINPUT), service, CHANGE); // Attach interrupt
    while (1) {
        // Do other, more important things here.
        delay(500);
    }
}

You should be able to instantiate several of these in the same sketch and define service methods to call each instances service functions, then attach them to interrupts in your main().

Explanations of the constructor arguments are in the header file.

About

An Arduino library for interfacing with things that output PWM signals.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages