MTsoftPWM
Event management for Uno, Nano, Mega

This PWM is managed soft, therefore usable on all pins independently. Possible periods from 200µs to 5 days.

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
level_and_stop
levels_and_stop
start_with

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

Constructor

MTsoftPWM(pin, 
          inpulseMicrosecond = 10000 µs,
          periodMicrosecond = 20000 µs,
          start = HIGH,
          numberOfChanges = MT_INFINI,
          onStopFunction = NO_ACTION,
          active = MT_ON);

Useful functions

void setInpulse(float inpulseMicrosecond);
void setDutyCycle(float dutyCycle);
void setPeriod(float periodMicrosecond);
void detach(void);
void attach(void);
void onStop(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
onStop: changes the function called when numberOfChanges/2 inpulses are done

Bonus functions

float getInpulse(void);
float getPeriod(void);
float getDutyCycle(void);
float getResolution(void);
void setNumberOfChanges(unsigned long numberOfChanges);
unsigned long getNumberOfChanges(void);
unsigned long getNumberOfChangesRemains(void);
void stop(void);
void start(void);
boolean getActive(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)
setNumberOfChanges: change the number of changes before stop
getNumberOfChanges: return the programmed number of changes
getNumberOfChangesRemains: returns the number of levels that remains to be made
stop: suspends activity
start: resumes the activity
getActive: retourne true if active

Examples