{"id":19,"date":"2013-10-25T03:52:43","date_gmt":"2013-10-25T03:52:43","guid":{"rendered":"http:\/\/mypocket-technologies.com\/?p=749"},"modified":"2013-10-25T03:52:43","modified_gmt":"2013-10-25T03:52:43","slug":"simple-audio-board","status":"publish","type":"post","link":"https:\/\/bitcows.com\/?p=19","title":{"rendered":"Simple Audio Board"},"content":{"rendered":"<p>Another project I did for a friend of mine was called &#8220;Rick Roll&#8221;. It&#8217;s basically a board that just plays a Rick Astley song.<br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-752\" title=\"rick-astley\" src=\"http:\/\/mypocket-technologies.com\/wp-content\/uploads\/2013\/10\/rick-astley.jpg\" alt=\"\" width=\"356\" height=\"237\" \/><\/p>\n<p><img decoding=\"async\" class=\"alignleft size-full wp-image-762\" title=\"rick roll\" src=\"http:\/\/mypocket-technologies.com\/wp-content\/uploads\/2013\/11\/IMG_5861.jpg\" alt=\"\" width=\"250\" \/><\/p>\n<p><img decoding=\"async\" class=\"alignleft size-full wp-image-760\" title=\"rick roll\" src=\"http:\/\/mypocket-technologies.com\/wp-content\/uploads\/2013\/11\/IMG_5851.jpg\" alt=\"\" width=\"250\" \/><\/p>\n<pre style=\"clear: both;\">\/*\nThis sketch uses the buzzer to play songs.\nThe Arduino's tone() command will play notes of a given frequency.\nWe'll provide a function that takes in note characters (a-g),\nand returns the corresponding frequency from this table:\n\n  note \tfrequency\n  c     262 Hz\n  d     294 Hz\n  e     330 Hz\n  f     349 Hz\n  g     392 Hz\n  a     440 Hz\n  b     494 Hz\n  C     523 Hz\n\nFor more information, see http:\/\/arduino.cc\/en\/Tutorial\/Tone\n*\/\n  \nconst int buzzerPin = 0;\nconst int ledPin = 1;\n\n\/\/ We'll set up an array with the notes we want to play\n\/\/ change these values to make different songs!\n\n\/\/ Length must equal the total number of notes and spaces \n\nconst int songLength = 18;\n\n\/\/ Notes is an array of text characters corresponding to the notes\n\/\/ in your song. A space represents a rest (no tone)\n\nchar notes[] = \"cdfda ag cdfdg gf \"; \/\/ a space represents a rest\n\n\/\/ Beats is an array values for each note and rest.\n\/\/ A \"1\" represents a quarter-note, 2 a half-note, etc.\n\/\/ Don't forget that the rests (spaces) need a length as well.\n\nint beats[] = {1,1,1,1,1,1,4,4,2,1,1,1,1,1,1,4,4,2};\n\n\/\/ The tempo is how fast to play the song.\n\/\/ To make the song play faster, decrease this value.\n\nint tempo = 150;\n\n\nvoid setup() \n{\n  \n  pinMode(buzzerPin, OUTPUT);\n  pinMode(ledPin, OUTPUT);\n}\n\n\nvoid loop() \n{\n  int i, duration;\n  \n  digitalWrite(ledPin,HIGH);\n  \n  for (i = 0; i &lt; songLength; i++) \/\/ step through the song arrays\n  {\n    duration = beats[i] * tempo;  \/\/ length of note\/rest in ms\n    \n    if (notes[i] == ' ')          \/\/ is this a rest? \n    {\n      delay(duration);            \/\/ then pause for a moment\n    }\n    else                          \/\/ otherwise, play the note\n    {\n      tone(buzzerPin, frequency(notes[i]), duration);\n      delay(duration); \/\/ wait for tone to finish\n    }\n    delay(tempo\/10);              \/\/ brief pause between notes\n  }\n  \n  digitalWrite(ledPin,LOW);\n  \/\/ We only want to play the song once, so we'll pause forever:\n  while(true){}\n  \/\/ If you'd like your song to play over and over,\n  \/\/ remove the above statement\n}\n\n\nint frequency(char note) \n{\n  \/\/ This function takes a note character (a-g), and returns the\n  \/\/ corresponding frequency in Hz for the tone() function.\n  \n  int i;\n  const int numNotes = 8;  \/\/ number of notes we're storing\n  \n  \/\/ The following arrays hold the note characters and their\n  \/\/ corresponding frequencies. The last \"C\" note is uppercase\n  \/\/ to separate it from the first lowercase \"c\". If you want to\n  \/\/ add more notes, you'll need to use unique characters.\n\n  \/\/ For the \"char\" (character) type, we put single characters\n  \/\/ in single quotes.\n\n  char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C' };\n  int frequencies[] = {262, 294, 330, 349, 392, 440, 494, 523};\n  \n  \/\/ Now we'll search through the letters in the array, and if\n  \/\/ we find it, we'll return the frequency for that note.\n  \n  for (i = 0; i &lt; numNotes; i++)  \/\/ Step through the notes\n  {\n    if (names[i] == note)         \/\/ Is this the one?\n    {\n      return(frequencies[i]);     \/\/ Yes! Return the frequency\n    }\n  }\n  return(0);  \/\/ We looked through everything and didn't find it,\n              \/\/ but we still need to return a value, so return 0.\n}\n<\/pre>\n<p><strong>SCHEMA:<\/strong><br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-full wp-image-800\" style=\"border: 1px solid #ccc;\" title=\"rickschema\" src=\"http:\/\/mypocket-technologies.com\/wp-content\/uploads\/2013\/10\/rickschema.png\" alt=\"\" width=\"500\" height=\"327\" \/><\/p>\n<div style=\"clear: both;\"><strong>GET THE CODE:<\/strong><br \/>\n<a href=\"https:\/\/drive.google.com\/file\/d\/0B0Pe9d5xGLeQNS1STFRXRHZqU0k\/edit?usp=sharing\">RickRoll Code<\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Another project I did for a friend of mine was called &#8220;Rick Roll&#8221;. It&#8217;s basically a board that just plays a Rick Astley song. \/* This sketch uses the buzzer to play songs. The Arduino&#8217;s tone() command will play notes of a given frequency. We&#8217;ll provide a function that takes in note characters (a-g), and&hellip;<\/p>\n<p class=\"more-link\"><a href=\"https:\/\/bitcows.com\/?p=19\" class=\"themebutton\">Read More<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[33,45],"class_list":["post-19","post","type-post","status-publish","format-standard","hentry","category-electronics","tag-arduino","tag-electronics"],"_links":{"self":[{"href":"https:\/\/bitcows.com\/index.php?rest_route=\/wp\/v2\/posts\/19","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bitcows.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bitcows.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bitcows.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bitcows.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=19"}],"version-history":[{"count":0,"href":"https:\/\/bitcows.com\/index.php?rest_route=\/wp\/v2\/posts\/19\/revisions"}],"wp:attachment":[{"href":"https:\/\/bitcows.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=19"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bitcows.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=19"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bitcows.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=19"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}