Advertisement
Guest User

Untitled

a guest
Nov 18th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.30 KB | None | 0 0
  1. //**** début du programme *********//
  2.  
  3. const float c = 261;
  4. const float d = 294;
  5. const float e = 329;
  6. const float f = 349;
  7. const float g = 391;
  8. const float gS = 415;
  9. const float a = 440;
  10. const float aS = 455;
  11. const float b = 466;
  12. const float cH = 523;
  13. const float cSH = 554;
  14. const float dH = 587;
  15. const float dSH = 622;
  16. const float eH = 659;
  17. const float fH = 698;
  18. const float fSH = 740;
  19. const float gH = 784;
  20. const float gSH = 830;
  21. const float aH = 880;
  22.  
  23. int BUZZER_PIN = 3;     // adresse du Buzzer (PIN) //
  24. int Bp1 = 10;        // adresse du BP1 (bouton poussoir 1)  (PIN) //
  25. int appui_bp1 = 0;       // variable de l'état de l'appui sur le BP1//
  26. //float demi_periode = (2.27e-3)*1000000;     // variable pour son//
  27. //float temps=2000;      //temps du son en milliseconde//
  28. //float duree = 0;     //variable de calcul du temps de fonctionnement du buzzer//
  29.  
  30. void allu_buzzer (int adress_buzzer, float freq, float temps_buz)
  31. {
  32.     float duree = 0;
  33.     while(duree < temps_buz*1000)
  34.     {
  35.       digitalWrite(adress_buzzer,HIGH); //
  36.       delayMicroseconds((2/freq)*1000000);
  37.       digitalWrite(adress_buzzer,LOW);
  38.       delayMicroseconds((2/freq)*1000000);
  39.       duree = duree + ((1/freq)*1000000);
  40.     }
  41. }
  42. void setup()
  43. {
  44.   pinMode(BUZZER_PIN, OUTPUT);   // adressage du Buzzer//
  45.   pinMode(Bp1,INPUT);   // adressage BP1 (bouton poussoir 1) //
  46.   digitalWrite(Bp1,HIGH);   // Simule la resistance de tirage du BP1//
  47. }
  48.  
  49. void loop()
  50. {
  51.   appui_bp1= digitalRead(Bp1); // lecture de l'état du BP1//
  52.  
  53.   if (appui_bp1 == LOW) // test si appui sur BP//
  54.   {
  55.     allu_buzzer(BUZZER_PIN, a, 500);
  56.     allu_buzzer(BUZZER_PIN, a, 500);
  57.     allu_buzzer(BUZZER_PIN, a, 500);
  58.     allu_buzzer(BUZZER_PIN, f, 350);
  59.     allu_buzzer(BUZZER_PIN, cH, 150);
  60.     allu_buzzer(BUZZER_PIN, a, 500);
  61.     allu_buzzer(BUZZER_PIN, f, 350);
  62.     allu_buzzer(BUZZER_PIN, cH, 150);
  63.     allu_buzzer(BUZZER_PIN, a, 650);
  64.     delay (500);
  65.     allu_buzzer(BUZZER_PIN,eH, 500);
  66.     allu_buzzer(BUZZER_PIN,eH, 500);
  67.     allu_buzzer(BUZZER_PIN,eH, 500);
  68.     allu_buzzer(BUZZER_PIN,fH, 350);
  69.     allu_buzzer(BUZZER_PIN,cH, 150);
  70.     allu_buzzer(BUZZER_PIN,gS, 500);
  71.     allu_buzzer(BUZZER_PIN,f, 350);
  72.     allu_buzzer(BUZZER_PIN,cH, 150);
  73.     allu_buzzer(BUZZER_PIN,a, 650);
  74.   }  
  75. }
  76. //**** fin du programme *********//
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement