Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Déclaration des variables
- int ledpin = 11;
- int switchpin = 2;
- int var=0, i=0, etat=0;
- int fadeAmount=8;
- const int LED=11;
- const int SWITCH=2;
- //Fonction timer
- void timer()
- {
- i++;
- delay(100); //Attente de 100ms
- if(i==250) //Rechargement de i par la valeur de 0 quand i = 60
- {
- i=0;
- }
- }
- void setup()
- {
- Serial.begin(9600);
- pinMode(LED,OUTPUT);
- pinMode(SWITCH,OUTPUT);
- }
- void loop()
- {
- timer(); //Utilisation de la fonction timer
- if((digitalRead(SWITCH)==LOW)&&(etat==0)) //Simulation porte ouverte
- {
- i=0;
- etat=1;
- var=0;
- }
- if((digitalRead(SWITCH)==LOW)&&(etat==1)) //Simulation porte ouverte
- {
- if(i<30)
- {
- var=var+fadeAmount;
- }
- if(var>=200)
- {
- var=250;
- }
- }
- if((digitalRead(SWITCH)==HIGH)&&(etat==1)) //Porte fermé
- {
- i=0;
- etat=0;
- }
- if((digitalRead(SWITCH)==HIGH)&&(etat==0)) //Simulation porte ouverte
- {
- if(i<32)
- {
- var=var-fadeAmount;
- }
- if(var<=10)
- {
- var=0;
- }
- }
- analogWrite(LED,var);
- Serial.println(var);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement