You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.8 KiB

5 years ago
  1. #include "notes.h"
  2. int tempo=144;
  3. int melody[] = {
  4. NOTE_E5, 4, NOTE_B4,8, NOTE_C5,8, NOTE_D5,4, NOTE_C5,8, NOTE_B4,8,
  5. NOTE_A4, 4, NOTE_A4,8, NOTE_C5,8, NOTE_E5,4, NOTE_D5,8, NOTE_C5,8,
  6. NOTE_B4, -4, NOTE_C5,8, NOTE_D5,4, NOTE_E5,4,
  7. NOTE_C5, 4, NOTE_A4,4, NOTE_A4,8, NOTE_A4,4, NOTE_B4,8, NOTE_C5,8,
  8. NOTE_D5, -4, NOTE_F5,8, NOTE_A5,4, NOTE_G5,8, NOTE_F5,8,
  9. NOTE_E5, -4, NOTE_C5,8, NOTE_E5,4, NOTE_D5,8, NOTE_C5,8,
  10. NOTE_B4, 4, NOTE_B4,8, NOTE_C5,8, NOTE_D5,4, NOTE_E5,4,
  11. NOTE_C5, 4, NOTE_A4,4, NOTE_A4,4, REST, 4,
  12. NOTE_E5, 4, NOTE_B4,8, NOTE_C5,8, NOTE_D5,4, NOTE_C5,8, NOTE_B4,8,
  13. NOTE_A4, 4, NOTE_A4,8, NOTE_C5,8, NOTE_E5,4, NOTE_D5,8, NOTE_C5,8,
  14. NOTE_B4, -4, NOTE_C5,8, NOTE_D5,4, NOTE_E5,4,
  15. NOTE_C5, 4, NOTE_A4,4, NOTE_A4,8, NOTE_A4,4, NOTE_B4,8, NOTE_C5,8,
  16. NOTE_D5, -4, NOTE_F5,8, NOTE_A5,4, NOTE_G5,8, NOTE_F5,8,
  17. NOTE_E5, -4, NOTE_C5,8, NOTE_E5,4, NOTE_D5,8, NOTE_C5,8,
  18. NOTE_B4, 4, NOTE_B4,8, NOTE_C5,8, NOTE_D5,4, NOTE_E5,4,
  19. NOTE_C5, 4, NOTE_A4,4, NOTE_A4,4, REST, 4,
  20. NOTE_E5,2, NOTE_C5,2,
  21. NOTE_D5,2, NOTE_B4,2,
  22. NOTE_C5,2, NOTE_A4,2,
  23. NOTE_GS4,2, NOTE_B4,4, REST,8,
  24. NOTE_E5,2, NOTE_C5,2,
  25. NOTE_D5,2, NOTE_B4,2,
  26. NOTE_C5,4, NOTE_E5,4, NOTE_A5,2,
  27. NOTE_GS5,2,
  28. };
  29. int notes=sizeof(melody)/sizeof(melody[0])/2;
  30. int wholenote = (60000 * 4) / tempo;
  31. int divider = 0, noteDuration = 0;
  32. void playTetris(){
  33. for (int thisNote = 0; thisNote < notes * 2; thisNote = thisNote + 2) {
  34. divider = melody[thisNote + 1];
  35. if (divider > 0) {
  36. noteDuration = (wholenote) / divider;
  37. } else if (divider < 0) {
  38. noteDuration = (wholenote) / abs(divider);
  39. noteDuration *= 1.5;
  40. }
  41. tone(15, melody[thisNote], noteDuration*0.9);
  42. delay(noteDuration);
  43. noTone(15);
  44. }
  45. }