MTcheckButton: Example 1
Event management for Uno, Nano, Mega

Turn on/off an LED

A button is connected between A0 and GND. The program will light the LED_BUILTIN LED when pressing the button. The LED will go out if you press a second time. It's like a light button.

Complete program recommended

This program is completely under interruption, and releases loop which can be used to do something else.

// This program will turn on/off an LED

#include <MTobjects.h> // V1.0.6 See http://arduino.dansetrad.fr/en/MTobjects

const uint8_t PIN_BUTTON = A0; // Button wired between A0 and GND


void light(void) // Call when press the button the first time
{
  digitalWrite(LED_BUILTIN, HIGH); // Light the LED
}

void turnOff(void) // Call when press the button the second time
{
  digitalWrite(LED_BUILTIN, LOW); // Turn off the LED
}

MTcheckButton Bouton(PIN_BUTTON, light, turnOff);



void setup()
{
  pinMode(LED_BUILTIN, OUTPUT); // LED initialization
}

void loop(){}