MThardPWM
Event management for Uno, Nano, Mega

Generates a PWM signal with a 16-bit timer.

Include to add

#include <MTobjects.h> // See http://arduino.dansetrad.fr/en/MTobjects

I strongly advise to leave the comment, if another person wanted to try the program, they would have a download link directly. This is valid for all the libraries you use.

Useful comments

micro_second
micro_seconds
inpulse_width
inpulses_width
period_width
periods_width
per_cent

These comments are words that can be added anywhere and which are ignored by the compiler.

Constructor

MThardPWM(pin, 
          periodMicrosecond = 20000 μs,
          inpulseMicrosecond = 10000 μs);

Useful functions

void setInpulse(float inpulseMicrosecond);
void setDutyCycle(float dutyCycle);
void setPeriod(float periodMicrosecond);
void detach(void);
void attach(void);

setInpulse: change the inpulse width
setInpulse: without parameter set inpulse width to 10ms
setDutyCycle: change the inpulse width with a duty cycle
setDutyCycle: without parameter set a 50% duty cycle 50%
setPeriod: change the period
setPeriod: without parameter set a 20ms period (50Hz)
detach: Disconnects the pin, it becomes "normal" as a starter (does not erase times programmed)
attach: Reconnect the pin, if it was detached

Bonus functions

float getInpulse(void);
float getPeriod(void);
float getDutyCycle(void);
float getResolution(void);

getInpulse: return the inpulse width
getPeriod: return the period
getDutyCycle: return the duty cycle
getResolution: returns the resolution in μs (between 62.5ns and 64μs)

Examples