MTservo
Event management for Uno, Nano, Mega
This object offers the management of classic servo (3 wires) 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 comment
micro_seconds milli_seconds milli_seconds_for_go_from_0_to_180 micro_seconds_initially degree_initially micro_seconds_minimum micro_seconds_maximum micro_seconds_per_period
These comments are words that can be added anywhere and which are ignored by the compiler.
Constructor
MTservo(pin, timeFrom0To180Millisecond = 1000 ms, onStopFunction = NO_ACTION, initialInpulse = 1500 µs, minInpulseMicroseconds = 500 µs, maxInpulseMicroseconds = 2500 µs, periodMicroseconds = 20000 µs);
- pin (uint8_t): Arduino pin Uno/Nano: 9, 10 Mega: 2, 3, 5, 6, 7, 8, 11, 12, 13, 44, 45, 46
- timeFrom0To180Millisecond (word): time to go from 0° to 180°
- onStopFunction: what happens when the servo arrives in position and initialization
- NO_ACTION → nothing happens
- myFunction → call a function "void myFunction(void) {...}"
- initialInpulse (word): fix the position at the power on. In µs or degree
- minInpulseMicroseconds (word): minimum duration of the inpulse
- maxInpulseMicroseconds (word): maximum duration of the inpulse
- periodMicroseconds (word): fix the period, maximum 32000µs
Useful functions
void writeDegree(word value); void writeMicrosecond(word value); void detach(void); void attach(void); void onStop(void);
writeDegree: go to the position requested in degree (or µs)
writeMicrosecond: go to the position requested in µs (or degree)
detach: disconnects the pin, it becomes "normal" as a starter (does not erase the scheduled times)
attach: reconnect the pin, if it was detached
onStop: function to be overloaded called when you have just finished the movement (and initialization)
Bonus functions
void setTimeFrom0To180(word timeFrom0To180Millisecond); word getTimeFrom0To180(void); void setMinInpulseMicroseconds(word minInpulseMicroseconds); word getMinInpulseMicroseconds(void); void setMaxInpulseMicroseconds(word maxInpulseMicroseconds); word getMaxInpulseMicroseconds(void); void setPeriod(word periodMicroseconds); word getPeriod(void); boolean getRun(void);
setTimeFrom0To180: fixes the speed of movement
setTimeFrom0To180: without parameters, fixes the speed of movement at 1s for a displacement of 180 °
getTimeFrom0To180: get the movement speed in ms
setMinInpulseMicroseconds: fix the minimum duration of the inpulse
setMinInpulseMicroseconds: without parameters, fix the minimum duration of the inpulse at 500µs
getMinInpulseMicroseconds: get the minimum duration of the inpulse in µs
setMaxInpulseMicroseconds: fix the maximum duration of the inpulse
setMaxInpulseMicroseconds: without parameters, fix the maximum duration of the inpulse at 2500µs
getMaxInpulseMicroseconds: get the minimum duration of the inpulse in µs
setPeriod: fix the period of the inpulses
setPeriod: without parameters, fix the period of the inpulses at 20ms
getPeriod: get the period of the inpulses
getRun: true if he moves, false if he is stops
Examples