Advertisement
weaknetlabs

Friday the 13th Cabin Box (Arduino Code)

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