Advertisement
Guest User

Untitled

a guest
Nov 18th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 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(((1/freq)/2)*1000000);
  37. digitalWrite(adress_buzzer,LOW);
  38. delayMicroseconds(((1/freq)/2)*1000000);
  39. duree = duree + ((1/freq)*1000000);
  40. }
  41. // Pour bien séparer les notes
  42. delayMicroseconds(temps_buz/10);
  43. }
  44. void setup()
  45. {
  46. pinMode(BUZZER_PIN, OUTPUT); // adressage du Buzzer//
  47. pinMode(Bp1,INPUT); // adressage BP1 (bouton poussoir 1) //
  48. digitalWrite(Bp1,HIGH); // Simule la resistance de tirage du BP1//
  49. }
  50.  
  51. void loop()
  52. {
  53. appui_bp1= digitalRead(Bp1); // lecture de l'état du BP1//
  54.  
  55. if (appui_bp1 == LOW) // test si appui sur BP//
  56. {
  57. allu_buzzer(BUZZER_PIN, a, 500);
  58. allu_buzzer(BUZZER_PIN, a, 500);
  59. allu_buzzer(BUZZER_PIN, a, 500);
  60. allu_buzzer(BUZZER_PIN, f, 350);
  61. allu_buzzer(BUZZER_PIN, cH, 150);
  62. allu_buzzer(BUZZER_PIN, a, 500);
  63. allu_buzzer(BUZZER_PIN, f, 350);
  64. allu_buzzer(BUZZER_PIN, cH, 150);
  65. allu_buzzer(BUZZER_PIN, a, 650);
  66. delay (500);
  67. allu_buzzer(BUZZER_PIN,eH, 500);
  68. allu_buzzer(BUZZER_PIN,eH, 500);
  69. allu_buzzer(BUZZER_PIN,eH, 500);
  70. allu_buzzer(BUZZER_PIN,fH, 350);
  71. allu_buzzer(BUZZER_PIN,cH, 150);
  72. allu_buzzer(BUZZER_PIN,gS, 500);
  73. allu_buzzer(BUZZER_PIN,f, 350);
  74. allu_buzzer(BUZZER_PIN,cH, 150);
  75. allu_buzzer(BUZZER_PIN,a, 650);
  76. }
  77. }
  78. //**** fin du programme *********//
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement