Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //**** début du programme *********//
- const float c = 261;
- const float d = 294;
- const float e = 329;
- const float f = 349;
- const float g = 391;
- const float gS = 415;
- const float a = 440;
- const float aS = 455;
- const float b = 466;
- const float cH = 523;
- const float cSH = 554;
- const float dH = 587;
- const float dSH = 622;
- const float eH = 659;
- const float fH = 698;
- const float fSH = 740;
- const float gH = 784;
- const float gSH = 830;
- const float aH = 880;
- int BUZZER_PIN = 3; // adresse du Buzzer (PIN) //
- int Bp1 = 10; // adresse du BP1 (bouton poussoir 1) (PIN) //
- int appui_bp1 = 0; // variable de l'état de l'appui sur le BP1//
- //float demi_periode = (2.27e-3)*1000000; // variable pour son//
- //float temps=2000; //temps du son en milliseconde//
- //float duree = 0; //variable de calcul du temps de fonctionnement du buzzer//
- void allu_buzzer (int adress_buzzer, float freq, float temps_buz)
- {
- float duree = 0;
- while(duree < temps_buz*1000)
- {
- digitalWrite(adress_buzzer,HIGH); //
- delayMicroseconds((2/freq)*1000000);
- digitalWrite(adress_buzzer,LOW);
- delayMicroseconds((2/freq)*1000000);
- duree = duree + ((1/freq)*1000000);
- }
- }
- void setup()
- {
- pinMode(BUZZER_PIN, OUTPUT); // adressage du Buzzer//
- pinMode(Bp1,INPUT); // adressage BP1 (bouton poussoir 1) //
- digitalWrite(Bp1,HIGH); // Simule la resistance de tirage du BP1//
- }
- void loop()
- {
- appui_bp1= digitalRead(Bp1); // lecture de l'état du BP1//
- if (appui_bp1 == LOW) // test si appui sur BP//
- {
- allu_buzzer(BUZZER_PIN, a, 500);
- allu_buzzer(BUZZER_PIN, a, 500);
- allu_buzzer(BUZZER_PIN, a, 500);
- allu_buzzer(BUZZER_PIN, f, 350);
- allu_buzzer(BUZZER_PIN, cH, 150);
- allu_buzzer(BUZZER_PIN, a, 500);
- allu_buzzer(BUZZER_PIN, f, 350);
- allu_buzzer(BUZZER_PIN, cH, 150);
- allu_buzzer(BUZZER_PIN, a, 650);
- delay (500);
- allu_buzzer(BUZZER_PIN,eH, 500);
- allu_buzzer(BUZZER_PIN,eH, 500);
- allu_buzzer(BUZZER_PIN,eH, 500);
- allu_buzzer(BUZZER_PIN,fH, 350);
- allu_buzzer(BUZZER_PIN,cH, 150);
- allu_buzzer(BUZZER_PIN,gS, 500);
- allu_buzzer(BUZZER_PIN,f, 350);
- allu_buzzer(BUZZER_PIN,cH, 150);
- allu_buzzer(BUZZER_PIN,a, 650);
- }
- }
- //**** fin du programme *********//
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement