Advertisement
Guest User

array_musical

a guest
Nov 4th, 2018
326
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Musical Arpeggio: ii V I Progression
  2.  
  3. int noteC = 523;
  4. int noteD = 587;
  5. int noteE = 659;
  6. int noteF = 699;
  7. int noteG = 784;
  8. int noteA = 880;
  9. int noteB = 988;
  10. int noteChigh = 1047;
  11. int noteDhigh = 1175;
  12. int noteEhigh = 1319;
  13. int noteFhigh = 1397;
  14.  
  15. int dMinor[] = {noteD, noteF, noteA, noteChigh};
  16. int gSeven[] = {noteG, noteB, noteDhigh, noteFhigh};
  17. int cMaj[] = {noteC, noteE, noteG, noteB};
  18.  
  19. int wholeNote = 1000;
  20. int halfNote = 500;
  21. int quartNote = 250;
  22. int dotHalf = 750;
  23. int dotQuart = 375;
  24. int extraWhole = 1250;
  25. int eightNote = 125;
  26. int fiveBeats = 1250;
  27. int fourAndHalfBeats = 1125;
  28.  
  29. int outPin = 8;
  30. int noteLength = 500;
  31. int restLength = 500;
  32.  
  33. int melody[] = {noteD, noteF, noteA, noteF, noteD, noteChigh, noteF,
  34.                 noteG, noteB, noteDhigh, noteB, noteG, noteFhigh, noteB,
  35.                 noteC, noteE, noteG, noteE, noteC, noteB, noteE,
  36.                 noteC, noteE, noteG, noteE, noteC, noteB, noteE};
  37.                
  38. int durations[] = {quartNote, quartNote, quartNote, eightNote, eightNote, halfNote, halfNote,
  39.                    quartNote, quartNote, quartNote, eightNote, eightNote, halfNote, halfNote,
  40.                    quartNote, quartNote, quartNote, eightNote, eightNote, halfNote, halfNote,
  41.                    quartNote, quartNote, quartNote, eightNote, eightNote, halfNote, halfNote};
  42.  
  43. void setup() {
  44. }
  45.  
  46. void loop() {
  47.   playSequence();
  48.   noTone(outPin);
  49.   delay(2000);
  50.   chordDminor();
  51.   chordG7();
  52.   chordCmaj();
  53.   chordCmaj();
  54.   noTone(outPin);
  55.   delay(5000);
  56. }
  57.  
  58. void playSequence() {
  59.   for (int i = 0; i < 28; i++)
  60.   {
  61.     playNoteAndBeat(melody[i], durations[i]);
  62.   }
  63. }
  64.  
  65. void playNoteAndBeat(int pitch, int beat) {
  66.   tone(outPin, pitch);
  67.   delay(beat);
  68.  
  69.  
  70. }
  71.  
  72. void chordDminor() {
  73.   for (int i = 0; i < 4; i++)
  74.   {
  75.     playNote(dMinor[i]);
  76.   }  
  77. }
  78.  
  79. void chordG7() {
  80.   for (int i = 0; i < 4; i++)
  81.   {
  82.     playNote(gSeven[i]);
  83.   }  
  84. }
  85.  
  86. void chordCmaj() {
  87.   for (int i = 0; i < 4; i++)
  88.   {
  89.     playNote(cMaj[i]);
  90.   }  
  91. }
  92.  
  93. void playNote(int note) {
  94.   tone(outPin, note);
  95.   delay(noteLength);
  96.   noTone(outPin);  
  97.   delay(restLength);
  98. }
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement