//Controlling Led By Button //Turns on and off a LED ,when pressings button attach to pin12 //Website:www.abonnel.fr //2016.11.27.17.41 /**********************************/ const int keyPin = 13; //the number of the key pin const int ledPin = 12;//the number of the led pin int etatRelay = LOW; const int tempsAllumage = 6; //secondes int tempsAllumage_cours = 0; //temps en cours /**********************************/ void setup() { pinMode(keyPin,INPUT);//initialize the key pin as input pinMode(ledPin,OUTPUT);//initialize the led pin as output. Serial.begin(9600); // initialize serial communications at 9600 bps } /**********************************/ void loop() { int etatButton = digitalRead(keyPin); if(etatButton == HIGH ) { // Action quand on appuie sur le bouton etatRelay = !etatRelay; //actionner le relais digitalWrite(ledPin,etatRelay); //actionner la LED delay(1000); // attendre 1 sec tempsAllumage_cours = 0; // reintialiser le compteur } if (etatRelay == HIGH) { // Action si le relais est collé if (tempsAllumage - tempsAllumage_cours <= 0) { // Si le temps est écoulé etatRelay = LOW; // Eteindre le relais digitalWrite(ledPin,etatRelay);//Eteindre la LED delay(1000); // Attendre 1 sec } else { // Si le temps n'est pas écoulé tempsAllumage_cours++; delay(1000); // attendre 1 sec } } // Afficher les status sur le port Serie // Serial.print(etatRelay); // Serial.print(" "); // Serial.println(tempsAllumage - tempsAllumage_cours); } /************************************/