Advertisement
weaknetlabs

Friday the 13th Cabin Box (Arduino Code)

Oct 16th, 2014
719
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.46 KB | None | 0 0
  1. #include <Tone.h>
  2. /* Friday the 13th Cabin Theme -
  3.    Designed by Douglas Berdeaux.
  4.  
  5.                            ############################
  6.                           ##############################
  7.                           ##         >. .v.           ##
  8.                           ##       '_---VoV---_       ##
  9.                           ##      ' o         o ;     ##
  10.                           ##     ` o           o '    ##
  11.                           ##     . o   o   o   o .    ##
  12.                           ##   __.      ___      _    ##
  13.                           ##  '*>. o00o. - .o00o <*'  ##
  14.                           ##   `|  `00'     `00'  |   ##
  15.                           ##    .                .    ##
  16.                           ##    `  .  .  o  .  . '    ##
  17.                           ##     . o   o   o   o.     ##
  18.                           ##     `     o   o    '     ##
  19.                           ##      `    o   o   '      ##
  20.                           ##        `   _ _           ##
  21.                           ##            `-            ##
  22.                           ##############################
  23.                            ############################
  24.                            
  25.                            */
  26.  
  27.  
  28. Tone tone1;
  29. Tone tone2;
  30. int part1[] = {740,494,587}; // lead sections
  31. int part2[] = {659,466,554};
  32. int part3[] = {659,440,554};
  33. int part4[] = {622,440,523};
  34. int part5[] = {622,415,523};
  35. int part6[] = {554,392,466};
  36. int part6b[] = {554,415,523};
  37. int part7[] = {466,392,440}; // the bridge
  38. // dancing with Jason at the ball <3
  39. int part8[] = {784,392,523,698,392,523};
  40. int part9[] = {698,392,466,622,392,466};
  41. int part10[] = {622,349,415,587,349,415};
  42. int part11[] = {587,311,392,523,311,392};
  43.  
  44. //int bass[] = {247,233,220,262,208,196,208,196,173,156}; // MID bass sections
  45. // int bass[] = {123,116,110,131,104,98,104,98,87,78}; // LOW bass sections
  46. int bass[] = {122,116,110,131,104,98,104,98,87,78,156,92}; // LOW bass sections
  47.  
  48. void setup(void)
  49. {
  50.   tone1.begin(13);
  51.   tone2.begin(12);
  52.  
  53.   pinMode(2, INPUT);
  54.   pinMode(3, INPUT);
  55.   Serial.begin(9600);
  56. }
  57.  
  58. void loop(){
  59.   int buttonState = digitalRead(2);
  60.   if(buttonState == HIGH){
  61.     for(int i=1;i<=3;i++){
  62.       //verse1(0);
  63.       verse(1);
  64.       bridge();
  65.       ball();
  66.     }
  67.   }
  68. }
  69.  
  70. void bridge(void){
  71.  playSection(part7,5,4,3);
  72.  playSection(part7,13,4,3);
  73.  //delay(100);
  74. }
  75.  
  76. void ball(void){ // ball dancing, merry go-round.
  77.   playSection(part8,6,1,6);
  78.   playSection(part9,7,1,6);
  79.   playSection(part10,8,1,6);
  80.   playSection(part11,9,1,6);
  81.   playSection(part8,6,1,6);
  82.   playSection(part9,7,1,6);
  83.   playSection(part10,8,1,6);
  84.   playSection(part11,10,1,6);
  85. }
  86.  
  87. void verse(int last){ // first verse
  88.     playSection(part1,0,2,3); // melody array, bass, repeat #
  89.     playSection(part2,1,2,3);
  90.     playSection(part1,0,2,3);
  91.     playSection(part2,1,2,3);
  92.     playSection(part3,2,2,3);
  93.     playSection(part4,3,2,3);
  94.     playSection(part5,4,2,3);
  95.     if(last==0){
  96.       playSection(part6,5,2,3);
  97.     }else{
  98.      playSection(part6b,11,2,3);
  99.     }
  100. }
  101.  
  102. void playSection(int notes[],int bassNote,int repeat,int length){ // play notes
  103.    for(int j=0;j<repeat;j++){
  104.       if(bassNote != 13){
  105.         tone2.play(bass[bassNote],(length - 1 * 300)); // TODO: calculate how long to play bass
  106.       }
  107.      for(int i=0;i<=length-1;i++){
  108.  
  109.       tone1.play(notes[i]);
  110.       delay(300);
  111.       tone1.stop();
  112.     }
  113.    tone2.stop();
  114.   }  
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement