MTservo: Example 3
Event management for Uno, Nano, Mega
Change place with button
This program uses a servomotor that changes positions with each press on the button. We will use to do this an on/off button.
Complete program recommended
This program is completely under interruption, and releases loop which can be used to do something else.
// This program moves a 3-wires servo. Each press on the button changes position
#include <MTobjects.h> // V1.0.6 See http://arduino.dansetrad.fr/en/MTobjects
const uint8_t PIN_BOUTON = A0; // Connected between A0 and GND
const uint8_t PIN_SERVO = 9; // On Uno the usable commands pins are: 9, 10
// On Mega: 2, 3, 5, 6, 7, 8, 11, 12, 13, 44, 45, 46
MTservo Servo(PIN_SERVO, 2000 milli_seconds_for_go_from_0_to_180, NO_ACTION, 0 degree_initially);
void oneHundredAndEightyDegrees(void) // For position 180°
{
Servo.writeDegree(180);
}
void zeroDegree(void) // For position 0°
{
Servo.writeDegree(0);
}
MTcheckButton Bouton(PIN_BOUTON, oneHundredAndEightyDegrees, zeroDegree);
void setup(){}
void loop(){}