MTservo4wires
Event management for Uno, Nano, Mega
This object offers the management of 4-wires servo with a 16-bits timer. It is for a normal servo on which we united an additional wire on the medium point of the potentiometer which can thus inform of the position (feasible if the servo is powered in 5V). This allows immobility to power on.
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 micro_seconds_minimum micro_seconds_maximum micro_seconds_per_period cad_for_0_degree cad_for_180_degree
These comments are words that can be added anywhere and which are ignored by the compiler.
Constructor
MTsevo4fils(pin, pinPot, cadFor0degree, cadFor180degree, timeFrom0To180Millisecond = 1000 ms, onStopFunction = NO_ACTION, 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
- pinPot (uint8_t): analog pin of the middle point of the potentiometer
- cadFor0degree (word): value of analogRead(pinPot) for 0°
- cadFor180degree (word): value of analogRead(pinPot) for 180°
- 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) {...}"
- 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 valeur); void writeMicrosecond(word valeur); 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