Advertisement
GreenSeaCow

Untitled

Apr 25th, 2024
498
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 7.65 KB | None | 0 0
  1. // Define the pin connected to the piezo buzzer
  2. const int buzzerPin = 8;
  3.  
  4. const int noteC = 262;
  5. const int noteD = 294;
  6. const int noteE = 330;
  7. const int noteF = 349;
  8. const int noteG = 392;
  9. const int noteA = 440;
  10. const int noteBFlat = 466;
  11.  
  12. void setup() {
  13.   // Set the buzzer pin as an output:
  14.   pinMode(buzzerPin, OUTPUT);
  15. }
  16.  
  17. void loop() {
  18.  
  19.   tone(buzzerPin, noteC, 500);
  20.   delay(500);
  21.   noTone(buzzerPin);  // Stop any tone playing
  22.   delay(20);  // Delay between notes
  23.  
  24.   tone(buzzerPin, noteC, 250);
  25.   delay(250);
  26.   noTone(buzzerPin);  // Stop any tone playing
  27.   delay(20);  // Delay between notes
  28.  
  29.   tone(buzzerPin, noteD, 750);
  30.   delay(750);
  31.   noTone(buzzerPin);  // Stop any tone playing
  32.   delay(20);  // Delay between notes
  33.  
  34.   tone(buzzerPin, noteC, 750);
  35.   delay(750);
  36.   noTone(buzzerPin);  // Stop any tone playing
  37.   delay(20);  // Delay between notes
  38.  
  39.   tone(buzzerPin, noteF, 750);
  40.   delay(750);
  41.   noTone(buzzerPin);  // Stop any tone playing
  42.   delay(20);  // Delay between notes
  43.  
  44.   tone(buzzerPin, noteE, 1500);
  45.   delay(1500);
  46.   noTone(buzzerPin);  // Stop any tone playing
  47.   delay(20);  // Delay between notes
  48.  
  49.   //------------------------------------------
  50.  
  51.     tone(buzzerPin, noteC, 500);
  52.   delay(500);
  53.   noTone(buzzerPin);  // Stop any tone playing
  54.   delay(20);  // Delay between notes
  55.  
  56.   tone(buzzerPin, noteC, 250);
  57.   delay(250);
  58.   noTone(buzzerPin);  // Stop any tone playing
  59.   delay(20);  // Delay between notes
  60.  
  61.   tone(buzzerPin, noteD, 750);
  62.   delay(750);
  63.   noTone(buzzerPin);  // Stop any tone playing
  64.   delay(20);  // Delay between notes
  65.  
  66.   tone(buzzerPin, noteC, 750);
  67.   delay(750);
  68.   noTone(buzzerPin);  // Stop any tone playing
  69.   delay(20);  // Delay between notes
  70.  
  71.   tone(buzzerPin, noteG, 750);
  72.   delay(750);
  73.   noTone(buzzerPin);  // Stop any tone playing
  74.   delay(20);  // Delay between notes
  75.  
  76.   tone(buzzerPin, noteF, 1500);
  77.   delay(1500);
  78.   noTone(buzzerPin);  // Stop any tone playing
  79.   delay(20);  // Delay between notes
  80.  
  81.   //------------------------------------------
  82.  
  83.     tone(buzzerPin, noteC, 500);
  84.   delay(500);
  85.   noTone(buzzerPin);  // Stop any tone playing
  86.   delay(20);  // Delay between notes
  87.  
  88.   tone(buzzerPin, noteC, 250);
  89.   delay(250);
  90.   noTone(buzzerPin);  // Stop any tone playing
  91.   delay(20);  // Delay between notes
  92.  
  93.   tone(buzzerPin, (noteC + noteC), 750);
  94.   delay(750);
  95.   noTone(buzzerPin);  // Stop any tone playing
  96.   delay(20);  // Delay between notes
  97.  
  98.   tone(buzzerPin, noteA, 750);
  99.   delay(750);
  100.   noTone(buzzerPin);  // Stop any tone playing
  101.   delay(20);  // Delay between notes
  102.  
  103.   tone(buzzerPin, noteF, 750);
  104.   delay(750);
  105.   noTone(buzzerPin);  // Stop any tone playing
  106.   delay(20);  // Delay between notes
  107.  
  108.   tone(buzzerPin, noteE, 750);
  109.   delay(750);
  110.   noTone(buzzerPin);  // Stop any tone playing
  111.   delay(20);  // Delay between notes
  112.  
  113.   tone(buzzerPin, noteD, 1500);
  114.   delay(1500);
  115.   noTone(buzzerPin);  // Stop any tone playing
  116.   delay(20);  // Delay between notes
  117.  
  118.  
  119.   //------------------------------------------
  120.  
  121.   tone(buzzerPin, noteBFlat, 500);
  122.   delay(500);
  123.   noTone(buzzerPin);  // Stop any tone playing
  124.   delay(20);  // Delay between notes
  125.  
  126.   tone(buzzerPin, noteBFlat, 250);
  127.   delay(250);
  128.   noTone(buzzerPin);  // Stop any tone playing
  129.   delay(20);  // Delay between notes
  130.  
  131.   tone(buzzerPin, noteA, 750);
  132.   delay(750);
  133.   noTone(buzzerPin);  // Stop any tone playing
  134.   delay(20);  // Delay between notes
  135.  
  136.   tone(buzzerPin, noteF, 750);
  137.   delay(750);
  138.   noTone(buzzerPin);  // Stop any tone playing
  139.   delay(20);  // Delay between notes
  140.  
  141.   tone(buzzerPin, noteG, 750);
  142.   delay(750);
  143.   noTone(buzzerPin);  // Stop any tone playing
  144.   delay(20);  // Delay between notes
  145.  
  146.   tone(buzzerPin, noteF, 1500);
  147.   delay(1500);
  148.   noTone(buzzerPin);  // Stop any tone playing
  149.   delay(20);  // Delay between notes
  150.  
  151.   //------------------------------------------
  152.  
  153.  
  154. //Wait a few secs before restarting tune...
  155.  
  156.  delay(2000);
  157.  
  158.  //HigherOctave
  159.  
  160.    //------------------------------------------
  161.  
  162.      tone(buzzerPin, noteC*2, 500);
  163.   delay(500);
  164.   noTone(buzzerPin);  // Stop any tone playing
  165.   delay(20);  // Delay between notes
  166.  
  167.   tone(buzzerPin, noteC*2, 250);
  168.   delay(250);
  169.   noTone(buzzerPin);  // Stop any tone playing
  170.   delay(20);  // Delay between notes
  171.  
  172.   tone(buzzerPin, noteD*2, 750);
  173.   delay(750);
  174.   noTone(buzzerPin);  // Stop any tone playing
  175.   delay(20);  // Delay between notes
  176.  
  177.   tone(buzzerPin, noteC*2, 750);
  178.   delay(750);
  179.   noTone(buzzerPin);  // Stop any tone playing
  180.   delay(20);  // Delay between notes
  181.  
  182.   tone(buzzerPin, noteF*2, 750);
  183.   delay(750);
  184.   noTone(buzzerPin);  // Stop any tone playing
  185.   delay(20);  // Delay between notes
  186.  
  187.   tone(buzzerPin, noteE*2, 1500);
  188.   delay(1500);
  189.   noTone(buzzerPin);  // Stop any tone playing
  190.   delay(20);  // Delay between notes
  191.  
  192.   //------------------------------------------
  193.  
  194.     tone(buzzerPin, noteC*2, 500);
  195.   delay(500);
  196.   noTone(buzzerPin);  // Stop any tone playing
  197.   delay(20);  // Delay between notes
  198.  
  199.   tone(buzzerPin, noteC*2, 250);
  200.   delay(250);
  201.   noTone(buzzerPin);  // Stop any tone playing
  202.   delay(20);  // Delay between notes
  203.  
  204.   tone(buzzerPin, noteD*2, 750);
  205.   delay(750);
  206.   noTone(buzzerPin);  // Stop any tone playing
  207.   delay(20);  // Delay between notes
  208.  
  209.   tone(buzzerPin, noteC*2, 750);
  210.   delay(750);
  211.   noTone(buzzerPin);  // Stop any tone playing
  212.   delay(20);  // Delay between notes
  213.  
  214.   tone(buzzerPin, noteG*2, 750);
  215.   delay(750);
  216.   noTone(buzzerPin);  // Stop any tone playing
  217.   delay(20);  // Delay between notes
  218.  
  219.   tone(buzzerPin, noteF*2, 1500);
  220.   delay(1500);
  221.   noTone(buzzerPin);  // Stop any tone playing
  222.   delay(20);  // Delay between notes
  223.  
  224.   //------------------------------------------
  225.  
  226.     tone(buzzerPin, noteC*2, 500);
  227.   delay(500);
  228.   noTone(buzzerPin);  // Stop any tone playing
  229.   delay(20);  // Delay between notes
  230.  
  231.   tone(buzzerPin, noteC*2, 250);
  232.   delay(250);
  233.   noTone(buzzerPin);  // Stop any tone playing
  234.   delay(20);  // Delay between notes
  235.  
  236.   tone(buzzerPin, (noteC + noteC)*2, 750);
  237.   delay(750);
  238.   noTone(buzzerPin);  // Stop any tone playing
  239.   delay(20);  // Delay between notes
  240.  
  241.   tone(buzzerPin, noteA*2, 750);
  242.   delay(750);
  243.   noTone(buzzerPin);  // Stop any tone playing
  244.   delay(20);  // Delay between notes
  245.  
  246.   tone(buzzerPin, noteF*2, 750);
  247.   delay(750);
  248.   noTone(buzzerPin);  // Stop any tone playing
  249.   delay(20);  // Delay between notes
  250.  
  251.   tone(buzzerPin, noteE*2, 750);
  252.   delay(750);
  253.   noTone(buzzerPin);  // Stop any tone playing
  254.   delay(20);  // Delay between notes
  255.  
  256.   tone(buzzerPin, noteD*2, 1500);
  257.   delay(1500);
  258.   noTone(buzzerPin);  // Stop any tone playing
  259.   delay(20);  // Delay between notes
  260.  
  261.  
  262.   //------------------------------------------
  263.  
  264.   tone(buzzerPin, noteBFlat*2, 500);
  265.   delay(500);
  266.   noTone(buzzerPin);  // Stop any tone playing
  267.   delay(20);  // Delay between notes
  268.  
  269.   tone(buzzerPin, noteBFlat*2, 250);
  270.   delay(250);
  271.   noTone(buzzerPin);  // Stop any tone playing
  272.   delay(20);  // Delay between notes
  273.  
  274.   tone(buzzerPin, noteA*2, 750);
  275.   delay(750);
  276.   noTone(buzzerPin);  // Stop any tone playing
  277.   delay(20);  // Delay between notes
  278.  
  279.   tone(buzzerPin, noteF*2, 750);
  280.   delay(750);
  281.   noTone(buzzerPin);  // Stop any tone playing
  282.   delay(20);  // Delay between notes
  283.  
  284.   tone(buzzerPin, noteG*2, 750);
  285.   delay(750);
  286.   noTone(buzzerPin);  // Stop any tone playing
  287.   delay(20);  // Delay between notes
  288.  
  289.   tone(buzzerPin, noteF*2, 1500);
  290.   delay(1500);
  291.   noTone(buzzerPin);  // Stop any tone playing
  292.   delay(20);  // Delay between notes
  293.  
  294.   //------------------------------------------
  295.  
  296.  
  297. //Wait a few secs before restarting tune...
  298.  
  299.  delay(2000);
  300.  
  301.  
  302. }
  303.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement