Advertisement
Guest User

Untitled

a guest
Dec 17th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. //Déclaration des variables
  2. int ledpin = 11;
  3. int switchpin = 2;
  4. int var=0, i=0, etat=0;
  5. int fadeAmount=8;
  6. const int LED=11;
  7. const int SWITCH=2;
  8.  
  9. //Fonction timer
  10. void timer()
  11. {
  12. i++;
  13. delay(100); //Attente de 100ms
  14. if(i==250) //Rechargement de i par la valeur de 0 quand i = 60
  15. {
  16. i=0;
  17. }
  18. }
  19.  
  20. void setup()
  21. {
  22. Serial.begin(9600);
  23. pinMode(LED,OUTPUT);
  24. pinMode(SWITCH,OUTPUT);
  25. }
  26.  
  27. void loop()
  28. {
  29. timer(); //Utilisation de la fonction timer
  30.  
  31. if((digitalRead(SWITCH)==LOW)&&(etat==0)) //Simulation porte ouverte
  32. {
  33. i=0;
  34. etat=1;
  35. var=0;
  36. }
  37.  
  38. if((digitalRead(SWITCH)==LOW)&&(etat==1)) //Simulation porte ouverte
  39. {
  40. if(i<30)
  41. {
  42. var=var+fadeAmount;
  43. }
  44. if(var>=200)
  45. {
  46. var=250;
  47. }
  48. }
  49.  
  50. if((digitalRead(SWITCH)==HIGH)&&(etat==1)) //Porte fermé
  51. {
  52. i=0;
  53. etat=0;
  54. }
  55.  
  56. if((digitalRead(SWITCH)==HIGH)&&(etat==0)) //Simulation porte ouverte
  57. {
  58. if(i<32)
  59. {
  60. var=var-fadeAmount;
  61. }
  62. if(var<=10)
  63. {
  64. var=0;
  65. }
  66. }
  67. analogWrite(LED,var);
  68. Serial.println(var);
  69.  
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement