MTservo: Example 2
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 a simple button, type bell.
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 inversion(void) // Inversion of the position 0° <-> 180° { if (Servo.readDegree() < 90) Servo.writeDegree(180); else Servo.writeDegree(0); } MTbutton Bouton(PIN_BOUTON, inversion); void setup(){} void loop(){}