Advertisement
Guest User

Sumer_is_Icummen_In_6.ino

a guest
Jun 12th, 2013
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.66 KB | None | 0 0
  1. /*
  2. Summer is Icummen In - Part 6
  3. By Chris Chungbin
  4. Plays the second accompanying part of a piece of 13th-century polyphony
  5. */
  6.  
  7. unsigned long temp=360; //set note rate in bpm of the GCF of note duration
  8. unsigned int t=0; //time var in periods of the variable "temp"
  9.  
  10. float pitch[]= {523.25, 466.16, 523.25, 000.00, 349.23, 392.00, 349.32, 392.00, 466.16,
  11. 523.25, 466.16, 523.25, 000.00, 349.23, 392.00, 349.32, 392.00, 466.16,
  12. 523.25, 466.16, 523.25, 000.00, 349.23, 392.00, 349.32, 392.00, 466.16,
  13. 523.25, 466.16, 523.25, 000.00, 349.23, 392.00, 349.32, 392.00, 466.16,
  14. 523.25, 466.16, 523.25, 000.00, 349.23, 392.00, 349.32, 392.00, 466.16,
  15. 523.25, 466.16, 523.25, 000.00, 349.23, 392.00, 349.32, 392.00, 466.16,
  16. 523.25, 466.16, 523.25, 000.00, 349.23, 392.00, 349.32, 392.00, 466.16,
  17. 523.25, 466.16, 523.25, 000.00, 349.23, 392.00, 349.32, 392.00, 466.16,
  18. 523.25, 466.16, 523.25, 000.00, 349.23, 392.00, 349.32, 0}; //frequency of each note in Hz
  19. unsigned int time[]= {3, 3, 3, 3, 3, 3, 3, 2, 1,
  20. 3, 3, 3, 3, 3, 3, 3, 2, 1,
  21. 3, 3, 3, 3, 3, 3, 3, 2, 1,
  22. 3, 3, 3, 3, 3, 3, 3, 2, 1,
  23. 3, 3, 3, 3, 3, 3, 3, 2, 1,
  24. 3, 3, 3, 3, 3, 3, 3, 2, 1,
  25. 3, 3, 3, 3, 3, 3, 3, 2, 1,
  26. 3, 3, 3, 3, 3, 3, 3, 2, 1,
  27. 3, 3, 3, 3, 3, 3, 3, 1,1,1}; //duration of note in time rate periods - multiple of shortest note value - add 2 other elements after the last duration to allow index shifting later
  28.  
  29. void setup() {
  30. pinMode(8, OUTPUT); //audio out
  31. pinMode(7, INPUT); //sync pulse from syncing board
  32. pinMode(6, OUTPUT); //ready signal out to syncing board
  33. digitalWrite(6, LOW);
  34.  
  35.  
  36. temp=60000000/temp; //convert tempo to period in microseconds
  37.  
  38. for(int i=0; i<sizeof(pitch)/4; i++) {
  39. pitch[i]=pitch[i]/2;
  40. }
  41.  
  42. for(int i=sizeof(time)/2-1; i>0; i--) { //this and the next for() convert time[] to start time of note
  43. time[i]=time[i-1];
  44. }
  45. time[0]=0;
  46. for(int i=1; i<sizeof(time)/2-1; i++) {
  47. time[i]=time[i-1]+time[i];
  48. }
  49. digitalWrite(6, HIGH);
  50. }
  51.  
  52. void loop() {
  53. t=0;
  54. unsigned long s=micros(); //period start time
  55. unsigned long p=0; //period
  56. boolean in=0; //input
  57. boolean waiting=0; //ready to wait for next pulse?
  58. while(!in) {
  59. in=digitalRead(7);
  60. }
  61. digitalWrite(6,LOW);
  62. in=0;
  63. while(in) {
  64. in=digitalRead(7);
  65. }
  66. while(!in) {
  67. in=digitalRead(7);
  68. }
  69. unsigned long start=micros(); //start time recorded
  70.  
  71. for (int i=0; i<sizeof(pitch)/4; i++) {
  72. while(time[i+1]>t) {
  73. s=micros();
  74. in=digitalRead(7);
  75. if(waiting&&in) {
  76. t=t+1;
  77. waiting=0;
  78. }
  79. if(!(waiting||in)) {
  80. waiting=1;
  81. }
  82. if(pitch[i]==0) {
  83. }
  84. else {
  85. p=1000000/pitch[i];
  86. digitalWrite(8, HIGH);
  87. delayMicroseconds(p/3);
  88. digitalWrite(8, LOW);
  89. while(micros()-s<p) {
  90. //waits in this incredibly exciting loop until the current period is done
  91. }
  92. }
  93. }
  94. }
  95.  
  96. while(1) {
  97. }
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement