Eteindre une led malgré l'appui d'un bouton

Bonjour fishbrainz

Simplifies toi la vie, utilises la bibliothèque Button.h, autant prendre les bonnes habitudes tout de suite :wink:
Et ça donne ceci:

#include <Button.h>     // https://www.arduino.cc/reference/en/libraries/button/
const int buttonPin = 2; // Le pin où le bouton est connecté
const int relayPin = 12; // Le pin où le relais est connecté

Button bouton(buttonPin); // Connect your button between pin buttonPin and GND

unsigned long relaisTempo = 0;     // Temporisation du relais
unsigned long relaisMills = 0;     // Temporisation du relais, chrono

void setup()
{
	Serial.begin(115200);
	bouton.begin();
	pinMode(relayPin, OUTPUT); // Initialise le pin du relais comme sortie
	digitalWrite(relayPin, LOW); // Assurez-vous que la LED est éteinte au démarrage
}

void loop()
{

	if (bouton.pressed())
	{
		relaisTempo = 5000;
		relaisMills = millis();     // Démarrage du chrono
		digitalWrite(relayPin, HIGH); // Le relais tire
	}
	
	if (bouton.released())
	{
		relaisTempo = 1000;
		relaisMills = millis();     // Démarrage du chrono
		digitalWrite(relayPin, HIGH); // Le relais tire
	}

	//--------------------------------- Temporisation
	if (relaisTempo != 0)     // Si temporisation en cours
	{
		if (millis() - relaisMills >= relaisTempo)
		{
			digitalWrite(relayPin, LOW); // Le relais tombe
			relaisTempo = 0;     // Temporisation terminée
		}
	}
}

A+
Cordialement
jpbbricole