Advertisement
makispaiktis

ArduinoBasics - 9. Smoke on the water

Mar 24th, 2021 (edited)
510
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const int buzzer = 11;
  2. const int button = 6;
  3. bool isPressed;
  4. // Hertz of each note
  5. int G = 196;
  6. int B = 235;    // Yfesi
  7. int C = 262;
  8. int D = 276;    // Yfesi
  9. // Times
  10. int miso = 1200;
  11. int tetarto = 600;
  12. int ogdoo = 300;
  13. int pause = 50;
  14.  
  15. void setup()
  16. {
  17.   Serial.begin(9600);
  18.   pinMode(button, INPUT);
  19. }
  20.  
  21. void loop()
  22. {
  23.   isPressed = digitalRead(button);
  24.   if(isPressed == true){
  25.     Serial.println("Button is pressed. Music is ready");
  26.     // 1st part
  27.     tone(buzzer, G);
  28.     delay(tetarto);
  29.     tone(buzzer, B);
  30.     delay(tetarto);
  31.     tone(buzzer, C);
  32.     delay(1.5 * tetarto);
  33.     // 2nd part
  34.     tone(buzzer, G);
  35.     delay(tetarto);
  36.     tone(buzzer, B);
  37.     delay(tetarto);
  38.     tone(buzzer, D);
  39.     delay(ogdoo);
  40.     tone(buzzer, C);
  41.     delay(miso);
  42.     // 3rd part
  43.     tone(buzzer, G);
  44.     delay(tetarto);
  45.     tone(buzzer, B);
  46.     delay(tetarto);
  47.     tone(buzzer, C);
  48.     delay(1.5 * tetarto);
  49.     // 4th part
  50.     tone(buzzer, B);
  51.     delay(tetarto);
  52.     tone(buzzer, G);
  53.     delay(miso);
  54.     noTone(buzzer);
  55.   }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement