{"id":2470,"date":"2020-10-26T07:44:12","date_gmt":"2020-10-26T14:44:12","guid":{"rendered":"http:\/\/www.donluc.com\/?p=2470"},"modified":"2020-10-26T07:44:12","modified_gmt":"2020-10-26T14:44:12","slug":"project-16-sound-simple-keyboard-mk04","status":"publish","type":"post","link":"https:\/\/www.donluc.com\/?p=2470","title":{"rendered":"Project #16: Sound &#8211; Simple Keyboard &#8211; Mk04"},"content":{"rendered":"<div style=\"width: 720px;\" class=\"wp-video\"><video class=\"wp-video-shortcode\" id=\"video-2470-1\" width=\"720\" height=\"406\" preload=\"metadata\" controls=\"controls\"><source type=\"video\/mp4\" src=\"https:\/\/www.donluc.com\/wp-content\/uploads\/2020\/10\/DL2010Mk03M.mp4?_=1\" \/><a href=\"https:\/\/www.donluc.com\/wp-content\/uploads\/2020\/10\/DL2010Mk03M.mp4\">https:\/\/www.donluc.com\/wp-content\/uploads\/2020\/10\/DL2010Mk03M.mp4<\/a><\/video><\/div>\n<p>&#8212;&#8212;<\/p>\n<p>#donluc #sound #synthesizer #simplekeyboard #programming #arduino #fritzing #electronics #microcontrollers #consultant #vlog<\/p>\n<p>&#8212;&#8212;<\/p>\n<p><a href=\"https:\/\/www.donluc.com\/wp-content\/uploads\/2020\/10\/DL2010Mk03a.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.donluc.com\/wp-content\/uploads\/2020\/10\/DL2010Mk03a.png\" alt=\"Simple Keyboard\" width=\"720\" height=\"477\" class=\"alignnone size-full wp-image-2472\" srcset=\"https:\/\/www.donluc.com\/wp-content\/uploads\/2020\/10\/DL2010Mk03a.png 720w, https:\/\/www.donluc.com\/wp-content\/uploads\/2020\/10\/DL2010Mk03a-300x199.png 300w\" sizes=\"auto, (max-width: 720px) 100vw, 720px\" \/><\/a><\/p>\n<p>&#8212;&#8212;<\/p>\n<p><a href=\"https:\/\/www.donluc.com\/wp-content\/uploads\/2020\/10\/DL2010Mk03b.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.donluc.com\/wp-content\/uploads\/2020\/10\/DL2010Mk03b.png\" alt=\"Simple Keyboard\" width=\"720\" height=\"480\" class=\"alignnone size-full wp-image-2473\" srcset=\"https:\/\/www.donluc.com\/wp-content\/uploads\/2020\/10\/DL2010Mk03b.png 720w, https:\/\/www.donluc.com\/wp-content\/uploads\/2020\/10\/DL2010Mk03b-300x200.png 300w\" sizes=\"auto, (max-width: 720px) 100vw, 720px\" \/><\/a><\/p>\n<p>&#8212;&#8212;<\/p>\n<p><a href=\"https:\/\/www.donluc.com\/wp-content\/uploads\/2020\/10\/DL2010Mk03c.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.donluc.com\/wp-content\/uploads\/2020\/10\/DL2010Mk03c.png\" alt=\"Simple Keyboard\" width=\"720\" height=\"480\" class=\"alignnone size-full wp-image-2474\" srcset=\"https:\/\/www.donluc.com\/wp-content\/uploads\/2020\/10\/DL2010Mk03c.png 720w, https:\/\/www.donluc.com\/wp-content\/uploads\/2020\/10\/DL2010Mk03c-300x200.png 300w\" sizes=\"auto, (max-width: 720px) 100vw, 720px\" \/><\/a><\/p>\n<p>&#8212;&#8212;<\/p>\n<p>While frequencies are represented with numbers (Hz), pitch is represented with letters. For example, if you have ever heard an orchestra \u2018tune\u2019 at the beginning of a concert, a single player plays an &#8220;A&#8221; measured at 440Hz. With pitch, we only use the letters A, B, C, D, E, F, and G. These pitches repeat every 8 notes, called an octave. In order to differentiate between which octaves we are referring to when talking about pitch, a number is added after the letter. Simply put in the 19th century and decided that was the case.<\/p>\n<p>One very important aspect of all music theory is that octaves are specifically defined as \u2018doubling\u2019 or \u2018halving\u2019 a pitch\u2019s frequency. For example, the frequencies 220 Hz, 440 Hz, and 880 Hz are all A\u2019s, but exist in different octaves: A3, A4, and A5 respectively. In Western music theory, we have generally<br \/>\nagreed that within each octave there are 12 equal subdivisions or pitches. So how do we determine where these other notes are \u2018tuned\u2019 in relationship to that A440.<\/p>\n<p><strong>Simple Keyboard<\/strong><\/p>\n<p>This simple keyboard how to use the tone() command to generate different pitches depending on which button is pressed. Connect each button to digital pins 2 => 9, using to ground on each input line. Connect digital pins two wires to the board. The first one black long vertical rows on the side of the breadboard to provide access to ground. The two wire goes from digital pin to one leg of the button. When the button is open (unpressed) there is no connection between the two legs of the button, so the pin is connected to ground and we read a LOW. When the button is closed (pressed), it makes a connection between its two legs. Connect one terminal of your speaker to digital pin 10 through and its other terminal to ground.<\/p>\n<p>The sketch uses an extra file, pitches.h. This file contains all the pitch values for typical notes. This note table on whose work the tone() command was based. You may find it useful for whenever you want to make musical notes. Player plays an NOTE_A4 measured at 440Hz, NOTE_B4 measured at 494Hz, NOTE_C5 measured at 523Hz, NOTE_D5 measured at 587Hz, NOTE_E5 measured at 659Hz, NOTE_F5 measured at 698Hz, NOTE_G5 measured at 784Hz and NOTE_A5 measured at 880Hz.<\/p>\n<p><strong>DL2010Mk03<\/strong><\/p>\n<p>1 x Arduino Pro Mini 328 &#8211; 5V\/16MHz<br \/>\n8 x Tactile Button<br \/>\n1 x Audio Jack 3.5mm<br \/>\n1 x SparkFun Audio Jack Breakout<br \/>\n1 x Hamburger Mini Speaker<br \/>\n8 x Wire Solid Core &#8211; 22 AWG<br \/>\n1 x Jumper Wires 3in M\/M<br \/>\n11 x Jumper Wires 6in M\/M<br \/>\n2 x Full-Size Breadboard<br \/>\n1 x SparkFun Cerberus USB Cable<br \/>\n1 x SparkFun FTDI Basic Breakout &#8211; 5V<\/p>\n<p><strong>Arduino Pro Mini 328 &#8211; 5V\/16MHz<\/strong><\/p>\n<p>SPK &#8211; Digital 10<br \/>\nKY2 &#8211; Digital 2<br \/>\nKY3 &#8211; Digital 3<br \/>\nKY4 &#8211; Digital 4<br \/>\nKY5 &#8211; Digital 5<br \/>\nKY6 &#8211; Digital 6<br \/>\nKY7 &#8211; Digital 7<br \/>\nKY8 &#8211; Digital 8<br \/>\nKY9 &#8211; Digital 9<br \/>\nVIN &#8211; +5V<br \/>\nGND &#8211; GND<\/p>\n<p><strong>DL2010Mk03p.ino<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">\r\n\/\/ ***** Don Luc Electronics \u00a9 *****\r\n\/\/ Software Version Information\r\n\/\/ Project #16: Sound - Simple Keyboard - Mk04\r\n\/\/ 10-03\r\n\/\/ DL2010Mk03p.ino 16-04\r\n\/\/ 1 x Arduino Pro Mini 328 - 5V\/16MHz\r\n\/\/ 8 x Tactile Button\r\n\/\/ 1 x Audio Jack 3.5mm\r\n\/\/ 1 x SparkFun Audio Jack Breakout\r\n\/\/ 1 x Hamburger Mini Speaker\r\n\/\/ 8 x Wire Solid Core - 22 AWG\r\n\/\/ 1 x Jumper Wires 3in M\/M\r\n\/\/ 11 x Jumper Wires 6in M\/M\r\n\/\/ 2 x Full-Size Breadboard\r\n\/\/ 1 x SparkFun Cerberus USB Cable\r\n\/\/ 1 x SparkFun FTDI Basic Breakout - 5V\r\n\r\n\/\/ Include the Library Code\r\n#include \"pitches.h\"\r\n\r\n\/\/ Mini Speaker\r\nint SPK = 10;\r\n\r\n\/\/ Simple Keyboard\r\n\/\/ Minimum reading of the button that generates a note\r\nconst int iKeyboard2 = 2;\r\nconst int iKeyboard3 = 3;\r\nconst int iKeyboard4 = 4;\r\nconst int iKeyboard5 = 5;\r\nconst int iKeyboard6 = 6;\r\nconst int iKeyboard7 = 7;\r\nconst int iKeyboard8 = 8;\r\nconst int iKeyboard9 = 9; \r\n\/\/ Button is pressed\r\nint aa = 1;\r\nint bb = 1;\r\nint cc = 1;\r\nint dd = 1;\r\nint ee = 1;\r\nint ff = 1;\r\nint gg = 1;\r\nint hh = 1;\r\n\r\n\/\/ Software Version Information\r\nString sver = \"16-04\";\r\n\r\nvoid loop() {\r\n\r\n  \/\/ Keyboard\r\n  isKeyboard();\r\n  \r\n}\r\n<\/pre>\n<p><strong>getKeyboard.1no<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">\r\n\/\/ getKeyboard\r\n\/\/ setupKeyboard\r\nvoid setupKeyboard() {\r\n\r\n  \/\/ Initialize the pushbutton pin as an input\r\n  pinMode(iKeyboard2, INPUT_PULLUP);\r\n  pinMode(iKeyboard3, INPUT_PULLUP);\r\n  pinMode(iKeyboard4, INPUT_PULLUP);\r\n  pinMode(iKeyboard5, INPUT_PULLUP);\r\n  pinMode(iKeyboard6, INPUT_PULLUP);\r\n  pinMode(iKeyboard7, INPUT_PULLUP);\r\n  pinMode(iKeyboard8, INPUT_PULLUP);\r\n  pinMode(iKeyboard9, INPUT_PULLUP);\r\n \r\n}\r\n\/\/ isKeyboard\r\nvoid isKeyboard() {\r\n\r\n  \/\/ Read the state of the pushbutton value\r\n  if ( digitalRead(iKeyboard2) == LOW ) {\r\n\r\n    \/\/ Button is pressed - pullup keeps pin high normally\r\n    aa = aa + 1;\r\n    tone(SPK, NOTE_A4, 20);\r\n    \r\n  }\r\n  else\r\n  {\r\n    \r\n    aa = aa - 1;\r\n    \r\n  }    \r\n\r\n  \/\/ Read the state of the pushbutton value\r\n  if ( digitalRead(iKeyboard3) == LOW ) {\r\n\r\n    \/\/ Button is pressed - pullup keeps pin high normally\r\n    bb = bb + 1;\r\n    tone(SPK, NOTE_B4, 20);\r\n    \r\n  }\r\n  else\r\n  {\r\n    \r\n    bb = bb - 1;\r\n    \r\n  }\r\n\r\n  \/\/ Read the state of the pushbutton value\r\n  if ( digitalRead(iKeyboard4) == LOW ) {\r\n\r\n    \/\/ Button is pressed - pullup keeps pin high normally\r\n    cc = cc + 1;\r\n    tone(SPK, NOTE_C5, 20);\r\n    \r\n  }\r\n  else\r\n  {\r\n    \r\n    cc = cc - 1;\r\n    \r\n  }\r\n\r\n  \/\/ Read the state of the pushbutton value\r\n  if ( digitalRead(iKeyboard5) == LOW ) {\r\n\r\n    \/\/ Button is pressed - pullup keeps pin high normally\r\n    dd = dd + 1;\r\n    tone(SPK, NOTE_D5, 20);\r\n    \r\n  }\r\n  else\r\n  {\r\n    \r\n    dd = dd - 1;\r\n    \r\n  }\r\n  \r\n  \/\/ Read the state of the pushbutton value\r\n  if ( digitalRead(iKeyboard6) == LOW ) {\r\n\r\n    \/\/ Button is pressed - pullup keeps pin high normally\r\n    ee = ee + 1;\r\n    tone(SPK, NOTE_E5, 20);\r\n    \r\n  }\r\n  else\r\n  {\r\n    \r\n    ee = ee - 1;\r\n    \r\n  }\r\n\r\n  \/\/ Read the state of the pushbutton value\r\n  if ( digitalRead(iKeyboard7) == LOW ) {\r\n\r\n    \/\/ Button is pressed - pullup keeps pin high normally\r\n    ff = ff + 1;\r\n    tone(SPK, NOTE_F5, 20);\r\n    \r\n  }\r\n  else\r\n  {\r\n    \r\n    ff = ff - 1;\r\n    \r\n  }\r\n\r\n  \/\/ Read the state of the pushbutton value\r\n  if ( digitalRead(iKeyboard8) == LOW ) {\r\n\r\n    \/\/ Button is pressed - pullup keeps pin high normally\r\n    gg = gg + 1;\r\n    tone(SPK, NOTE_G5, 20);\r\n    \r\n  }\r\n  else\r\n  {\r\n    \r\n    gg = gg - 1;\r\n    \r\n  }\r\n\r\n  \/\/ Read the state of the pushbutton value\r\n  if ( digitalRead(iKeyboard9) == LOW ) {\r\n\r\n    \/\/ Button is pressed - pullup keeps pin high normally\r\n    hh = hh + 1;\r\n    tone(SPK, NOTE_A5, 20);\r\n    \r\n  }\r\n  else\r\n  {\r\n    \r\n    hh = hh - 1;\r\n    \r\n  }\r\n\r\n  noTone(SPK);\r\n\r\n}\r\n<\/pre>\n<p><strong>pitches.h<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">\r\n\/*****************************************************************\r\n * Pitches NOTE_B0 <=> NOTE_DS8 - NOTE_A4 is \"A\" measured at 440Hz\r\n *****************************************************************\/\r\n\r\n#define NOTE_B0  31\r\n#define NOTE_C1  33\r\n#define NOTE_CS1 35\r\n#define NOTE_D1  37\r\n#define NOTE_DS1 39\r\n#define NOTE_E1  41\r\n#define NOTE_F1  44\r\n#define NOTE_FS1 46\r\n#define NOTE_G1  49\r\n#define NOTE_GS1 52\r\n#define NOTE_A1  55\r\n#define NOTE_AS1 58\r\n#define NOTE_B1  62\r\n#define NOTE_C2  65\r\n#define NOTE_CS2 69\r\n#define NOTE_D2  73\r\n#define NOTE_DS2 78\r\n#define NOTE_E2  82\r\n#define NOTE_F2  87\r\n#define NOTE_FS2 93\r\n#define NOTE_G2  98\r\n#define NOTE_GS2 104\r\n#define NOTE_A2  110\r\n#define NOTE_AS2 117\r\n#define NOTE_B2  123\r\n#define NOTE_C3  131\r\n#define NOTE_CS3 139\r\n#define NOTE_D3  147\r\n#define NOTE_DS3 156\r\n#define NOTE_E3  165\r\n#define NOTE_F3  175\r\n#define NOTE_FS3 185\r\n#define NOTE_G3  196\r\n#define NOTE_GS3 208\r\n#define NOTE_A3  220\r\n#define NOTE_AS3 233\r\n#define NOTE_B3  247\r\n#define NOTE_C4  262\r\n#define NOTE_CS4 277\r\n#define NOTE_D4  294\r\n#define NOTE_DS4 311\r\n#define NOTE_E4  330\r\n#define NOTE_F4  349\r\n#define NOTE_FS4 370\r\n#define NOTE_G4  392\r\n#define NOTE_GS4 415\r\n#define NOTE_A4  440\r\n#define NOTE_AS4 466\r\n#define NOTE_B4  494\r\n#define NOTE_C5  523\r\n#define NOTE_CS5 554\r\n#define NOTE_D5  587\r\n#define NOTE_DS5 622\r\n#define NOTE_E5  659\r\n#define NOTE_F5  698\r\n#define NOTE_FS5 740\r\n#define NOTE_G5  784\r\n#define NOTE_GS5 831\r\n#define NOTE_A5  880\r\n#define NOTE_AS5 932\r\n#define NOTE_B5  988\r\n#define NOTE_C6  1047\r\n#define NOTE_CS6 1109\r\n#define NOTE_D6  1175\r\n#define NOTE_DS6 1245\r\n#define NOTE_E6  1319\r\n#define NOTE_F6  1397\r\n#define NOTE_FS6 1480\r\n#define NOTE_G6  1568\r\n#define NOTE_GS6 1661\r\n#define NOTE_A6  1760\r\n#define NOTE_AS6 1865\r\n#define NOTE_B6  1976\r\n#define NOTE_C7  2093\r\n#define NOTE_CS7 2217\r\n#define NOTE_D7  2349\r\n#define NOTE_DS7 2489\r\n#define NOTE_E7  2637\r\n#define NOTE_F7  2794\r\n#define NOTE_FS7 2960\r\n#define NOTE_G7  3136\r\n#define NOTE_GS7 3322\r\n#define NOTE_A7  3520\r\n#define NOTE_AS7 3729\r\n#define NOTE_B7  3951\r\n#define NOTE_C8  4186\r\n#define NOTE_CS8 4435\r\n#define NOTE_D8  4699\r\n#define NOTE_DS8 4978\r\n<\/pre>\n<p><strong>setup.ino<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">\r\n\/\/ Setup\r\nvoid setup() {\r\n\r\n  \/\/ Setup Keyboard\r\n  setupKeyboard();\r\n  \r\n}\r\n<\/pre>\n<p><strong>Technology Experience<\/strong><\/p>\n<ul>\n<li>Single-Board Microcontrollers (PIC, Arduino, Raspberry Pi,Espressif, etc&#8230;)<\/li>\n<li>Robotics<\/li>\n<li>Research &#038; Development (R &#038; D)<\/li>\n<li>Desktop Applications (Windows, OSX, Linux, Multi-OS, Multi-Tier, etc&#8230;)<\/li>\n<li>Mobile Applications (Android, iOS, Blackberry, Windows Mobile, Windows CE, etc&#8230;)<\/li>\n<li>Web Applications (LAMP, Scripting, Java, ASP, ASP.NET, RoR, Wakanda, etc&#8230;)<\/li>\n<li>Social Media Programming &#038; Integration (Facebook, Twitter, YouTube, Pinterest, etc&#8230;)<\/li>\n<li>Content Management Systems (WordPress, Drupal, Joomla, Moodle, etc&#8230;)<\/li>\n<li>Bulletin Boards (phpBB, SMF, Vanilla, jobberBase, etc&#8230;)<\/li>\n<li>eCommerce (WooCommerce, OSCommerce, ZenCart, PayPal Shopping Cart, etc&#8230;)<\/li>\n<\/ul>\n<p><strong>Instructor<\/strong><\/p>\n<ul>\n<li>Arduino<\/li>\n<li>Raspberry Pi<\/li>\n<li>Espressif<\/li>\n<li>Robotics<\/li>\n<li>DOS, Windows, OSX, Linux, iOS, Android, Multi-OS<\/li>\n<li>Linux-Apache-PHP-MySQL<\/li>\n<\/ul>\n<p><strong>Follow Us<\/strong><\/p>\n<p><strong>J. Luc Paquin \u2013 Curriculum Vitae<\/strong><br \/>\nhttps:\/\/www.donluc.com\/DLHackster\/LucPaquinCVEngMk2020a.pdf<\/p>\n<p><strong>Web:<\/strong> https:\/\/www.donluc.com\/<br \/>\n<strong>Web:<\/strong> http:\/\/www.jlpconsultants.com\/<br \/>\n<strong>Web:<\/strong> https:\/\/www.donluc.com\/DLHackster\/<br \/>\n<strong>Web:<\/strong> https:\/\/www.hackster.io\/neosteam-labs<br \/>\n<strong>Facebook:<\/strong> https:\/\/www.facebook.com\/neosteam.labs.9\/<br \/>\n<strong>YouTube:<\/strong> https:\/\/www.youtube.com\/channel\/UC5eRjrGn1CqkkGfZy0jxEdA<br \/>\n<strong>Twitter:<\/strong> https:\/\/twitter.com\/labs_steam<br \/>\n<strong>Pinterest:<\/strong> https:\/\/www.pinterest.com\/NeoSteamLabs\/<br \/>\n<strong>Instagram:<\/strong> https:\/\/www.instagram.com\/luc.paquin\/<\/p>\n<p><strong>Don Luc<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#8212;&#8212; #donluc #sound #synthesizer #simplekeyboard #programming #arduino #fritzing #electronics #microcontrollers #consultant #vlog &#8212;&#8212; &#8212;&#8212; &#8212;&#8212; &#8212;&#8212; While frequencies are represented with numbers (Hz), pitch is represented with letters. For example, if you have ever heard an orchestra \u2018tune\u2019 at the beginning of a concert, a single player plays an &#8220;A&#8221; measured at 440Hz. With pitch, &#8230; <a title=\"Project #16: Sound &#8211; Simple Keyboard &#8211; Mk04\" class=\"read-more\" href=\"https:\/\/www.donluc.com\/?p=2470\" aria-label=\"Read more about Project #16: Sound &#8211; Simple Keyboard &#8211; Mk04\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[119,50,38,59,5,7,58,10,43,51],"tags":[6,102,19,85,24,25,9,27,123,120,109,34,108],"class_list":["post-2470","post","type-post","status-publish","format-standard","hentry","category-sound","category-arduino","category-digitalelectronics","category-fritzing","category-microcontrollers","category-musical-instruments","category-arduino-programming","category-projects","category-sparkfun","category-synth","tag-arduino","tag-components","tag-electronics","tag-fritzing","tag-microcontroller","tag-musical-instruments-2","tag-programming","tag-projects-2","tag-simple-keyboard","tag-sound","tag-sparkfun","tag-video-blog","tag-vlog"],"_links":{"self":[{"href":"https:\/\/www.donluc.com\/index.php?rest_route=\/wp\/v2\/posts\/2470","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.donluc.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.donluc.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.donluc.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.donluc.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2470"}],"version-history":[{"count":1,"href":"https:\/\/www.donluc.com\/index.php?rest_route=\/wp\/v2\/posts\/2470\/revisions"}],"predecessor-version":[{"id":2475,"href":"https:\/\/www.donluc.com\/index.php?rest_route=\/wp\/v2\/posts\/2470\/revisions\/2475"}],"wp:attachment":[{"href":"https:\/\/www.donluc.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2470"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.donluc.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2470"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.donluc.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2470"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}