{"id":3372,"date":"2023-03-04T06:19:01","date_gmt":"2023-03-04T14:19:01","guid":{"rendered":"https:\/\/www.donluc.com\/?p=3372"},"modified":"2023-03-04T06:19:01","modified_gmt":"2023-03-04T14:19:01","slug":"project-16-sound-metronome-mk22","status":"publish","type":"post","link":"https:\/\/www.donluc.com\/?p=3372","title":{"rendered":"Project #16: Sound &#8211; Metronome &#8211; Mk22"},"content":{"rendered":"<div style=\"width: 720px;\" class=\"wp-video\"><video class=\"wp-video-shortcode\" id=\"video-3372-1\" width=\"720\" height=\"480\" preload=\"metadata\" controls=\"controls\"><source type=\"video\/mp4\" src=\"https:\/\/www.donluc.com\/wp-content\/uploads\/2023\/03\/DL2301Mk03W.mp4?_=1\" \/><a href=\"https:\/\/www.donluc.com\/wp-content\/uploads\/2023\/03\/DL2301Mk03W.mp4\">https:\/\/www.donluc.com\/wp-content\/uploads\/2023\/03\/DL2301Mk03W.mp4<\/a><\/video><\/div>\n<p>&#8212;&#8212;<\/p>\n<p>#DonLucElectronics #DonLuc #Sound #Metronome #Project #Fritzing #Programming #Electronics #Microcontrollers #Consultant<\/p>\n<p>&#8212;&#8212;<\/p>\n<p><a href=\"https:\/\/www.donluc.com\/wp-content\/uploads\/2023\/03\/DL2301Mk03a.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.donluc.com\/wp-content\/uploads\/2023\/03\/DL2301Mk03a.png\" alt=\"Metronome\" width=\"720\" height=\"688\" class=\"alignnone size-full wp-image-3374\" srcset=\"https:\/\/www.donluc.com\/wp-content\/uploads\/2023\/03\/DL2301Mk03a.png 720w, https:\/\/www.donluc.com\/wp-content\/uploads\/2023\/03\/DL2301Mk03a-300x287.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\/2023\/03\/DL2301Mk03b.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.donluc.com\/wp-content\/uploads\/2023\/03\/DL2301Mk03b.png\" alt=\"Metronome\" width=\"720\" height=\"480\" class=\"alignnone size-full wp-image-3375\" srcset=\"https:\/\/www.donluc.com\/wp-content\/uploads\/2023\/03\/DL2301Mk03b.png 720w, https:\/\/www.donluc.com\/wp-content\/uploads\/2023\/03\/DL2301Mk03b-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\/2023\/03\/DL2301Mk03c.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.donluc.com\/wp-content\/uploads\/2023\/03\/DL2301Mk03c.png\" alt=\"Metronome\" width=\"720\" height=\"480\" class=\"alignnone size-full wp-image-3376\" srcset=\"https:\/\/www.donluc.com\/wp-content\/uploads\/2023\/03\/DL2301Mk03c.png 720w, https:\/\/www.donluc.com\/wp-content\/uploads\/2023\/03\/DL2301Mk03c-300x200.png 300w\" sizes=\"auto, (max-width: 720px) 100vw, 720px\" \/><\/a><\/p>\n<p>&#8212;&#8212;<\/p>\n<p><strong>Metronome<\/strong><\/p>\n<p>A metronome is a device that produces an audible click or other sound at a regular interval that can be set by the user, typically in Beats Per Minute (BPM). Metronomes may include synchronized visual motion. Musicians use the device to practise playing to a regular pulse. In the 20th century, electronic metronomes and software metronomes were invented.<\/p>\n<p>Musicians practise with metronomes to improve their timing, especially the ability to stick to a regular tempo. Metronome practice helps internalize a clear sense of timing and tempo. Composers and conductors often use a metronome as a standard tempo reference, and may play, sing, or conduct to the metronome. The metronome is used by composers to derive beats per minute if they want to indicate that in a composition. Conductors use a metronome to note their preferred tempo in each section.<\/p>\n<p><strong>SparkFun Metro-Gnome<\/strong><\/p>\n<p>The SparkFun Metro-Gnome is a basic digital metronome used to keep time during music practice. This is a basic kit that goes together in 15-20 minutes for people learning to solder, and 5-10 minutes for those with a bit of experience.<\/p>\n<p><strong>DL2301Mk03<\/strong><\/p>\n<p>-1 x Metro-Gnome PCB<br \/>\n-1 x ATmega168<br \/>\n-2 x 7-Segment Red LED<br \/>\n-1 x 10uF Capacitor<br \/>\n-1 X 0.1uf Capacitor<br \/>\n-1 x 10k Resistor<br \/>\n-1 x 1N4148 Diode<br \/>\n-1 x Piezo Speaker<br \/>\n-1 x Mini Power Switch<br \/>\n-2 x Push Button Reset Switches<br \/>\n-1 x Battery Holder Pack<br \/>\n-4 x AA Alkaline Battery<\/p>\n<p><strong>ATmega168<\/strong><\/p>\n<p>Metro-Gnome<br \/>\nVIN &#8211; +6V<br \/>\nGND &#8211; GND<\/p>\n<p>&#8212;&#8212;<\/p>\n<p><strong>Metrognomev03<\/strong><\/p>\n<p><strong>Metrognomev03.c<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"c\" data-enlighter-title=\"\">\r\n\/\/ Metronome-v03\r\n\r\n#define F_CPU 1024000\t\/\/ Adjust this to get the clock more precise\r\n\r\n#include &lt;avr\/io.h&gt;\r\n#include &lt;util\/delay.h&gt;\r\n#include &lt;avr\/interrupt.h&gt;\r\n\r\n#define BUZZER1 \t1\r\n#define BUZZER1_PORT\tPORTB\r\n#define BUZZER2\t\t2\r\n#define BUZZER2_PORT\tPORTB\r\n\r\n#define sbi(port_name, pin_number)   (port_name |= 1&lt;&lt;pin_number)\r\n#define cbi(port_name, pin_number)   ((port_name) &amp;= (uint8_t)~(1 &lt;&lt; pin_number))\r\n\r\nuint16_t countUp = F_CPU\/1024;\t\t\/\/ Dividing clock by 1024\r\nuint16_t speed = 60;\t\t\/\/ Program initially runs at 60 BPM\r\nuint8_t leftDisplay = 6;\t\t\/\/ Initialize output to show 60 BPM\r\nuint8_t rightDisplay = 0;\r\n\r\nvoid ioinit();\r\nvoid display(int digit, int number);\r\n\r\n\/\/ Interrupt Timer 1 makes the buzzer tick at proper intervals\r\nISR(TIMER1_COMPA_vect)\r\n{\r\n\tint buzzPeriod = 100;\r\n\tuint32_t buzzLength = 1000;\r\n\r\n\twhile(1)\r\n    {\r\n\t\t\/\/Subtract the buzzPeriod from the overall length\r\n\t\tif(buzzPeriod &gt; buzzLength) break;\r\n\t\tbuzzLength -= buzzPeriod;\r\n\r\n\t\tif(buzzPeriod &gt; buzzLength) break;\r\n\t\tbuzzLength -= buzzPeriod;\r\n\r\n\t\t\/\/Toggle the buzzer at various speeds\r\n\t\tPINB = 0b00000010;\r\n\t\t_delay_us(buzzPeriod);\r\n\t\t\r\n\t\tPINB = 0b00000100;\r\n\t\t_delay_us(buzzPeriod);\r\n    }\r\n}\r\n\r\n\/\/ Interrupt Timer 2 checks for button presses\r\nISR(TIMER0_COMPA_vect)\r\n{\r\n\t\/\/ Check down button\r\n    if( (PINB &amp; (1&lt;&lt;4)) == 0)\r\n\t{\r\n\t\tif (speed == 1)\t\t\/\/ If speed = 1 go up to 299\r\n\t\t{\r\n\t\t\tspeed = 299;\r\n\t\t\trightDisplay = 9;\r\n\t\t\tleftDisplay = 9;\r\n\t\t}\r\n\t\telse if ((rightDisplay == 0) &amp;&amp; (leftDisplay == 0))\r\n\t\t{\r\n\t\t\trightDisplay = 9;\r\n\t\t\tleftDisplay = 9;\r\n\t\t\tspeed--;\r\n\t\t}\r\n\t\telse if (rightDisplay == 0)\r\n\t\t{\r\n\t\t\trightDisplay = 9;\r\n\t\t\tleftDisplay--;\r\n\t\t\tspeed--;\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\trightDisplay--;\r\n\t\t\tspeed--;\r\n\t\t}\r\n\t\t\/\/ Reset counter and adjust compare register\r\n\t\tTCNT1 = 0x00;\r\n\t\tOCR1A = (countUp*60)\/speed;\r\n\t}\r\n\t\/\/ Check up button\r\n\tif((PINB &amp; (1&lt;&lt;5)) == 0)\r\n\t{\r\n\t\tif (speed == 299)\r\n\t\t{\r\n\t\t\tspeed = 1;\r\n\t\t\trightDisplay = 1;\r\n\t\t\tleftDisplay = 0;\r\n\t\t}\r\n\t\telse if ((rightDisplay == 9) &amp;&amp; (leftDisplay == 9))\r\n\t\t{\r\n\t\t\trightDisplay = 0;\r\n\t\t\tleftDisplay = 0;\r\n\t\t\tspeed++;\r\n\t\t}\t\t\r\n\t\telse if (rightDisplay == 9)\r\n\t\t{\r\n\t\t\trightDisplay = 0;\r\n\t\t\tleftDisplay++;\r\n\t\t\tspeed++;\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\trightDisplay++;\r\n\t\t\tspeed++;\r\n\t\t}\r\n\t\t\/\/ Reset counter and adjust compare register\r\n\t\tTCNT1 = 0x00;\r\n\t\tOCR1A = (countUp*60)\/speed;\r\n\t}\r\n}\r\n\r\nint main()\r\n{\r\n\tint flag = 0;\r\n\r\n\tioinit();\r\n\t\r\n\twhile(1)\t\/\/ Main loop PWM&#039;s the two displays at 1kHz\r\n\t{\r\n\t\tif (flag == 0)\r\n\t\t{\r\n\t\t\tcbi(PORTC, 1);\t\/\/ Turn right display off\r\n\t\t\tdisplay(0, leftDisplay);\t\/\/ Output to left display\r\n\t\t\tflag = 1;\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tcbi(PORTC, 0);\t\/\/ Turn left display off\r\n\t\t\tdisplay(1, rightDisplay);\t\/\/ Output to right display\r\n\t\t\tflag = 0;\r\n\t\t}\r\n\t\t_delay_us(10);\r\n\t\tPORTD = 0xFF;\r\n\t\tcbi(PORTC, 0);\r\n\t\tcbi(PORTC, 1);\r\n\t\t_delay_us(30);\r\n\t}\r\n\t\r\n\treturn 0;\r\n}\r\n\r\nvoid ioinit()\r\n{\r\n\t\/\/ set PORTB for Buzzer and buttons\r\n\tDDRB = DDRB | 0b00110110;\r\n\tPORTB = PORTB | 0b00110000;\r\n\t\/\/ set PORTC for DIGI select\r\n\tDDRC = 0b0000011;\r\n\tPINC = 0b0000011;\r\n\t\/\/ set PORTD for display\r\n\tDDRD = 0b11111111;\r\n\r\n\t\/\/ Set 16-bit Timer 1 for clicking\r\n\tTCCR1A = 0x00;\r\n\tTCCR1B = (_BV(WGM12) | _BV(CS12) | _BV(CS10));\t\/\/ Divide clock by 1024, CTC mode\r\n\tOCR1A = (countUp*60)\/speed;\t\/\/ Set top of counter\r\n\tTIMSK1 = _BV(OCIE1A);\t\/\/ Enable OCR1A interrupt\r\n\r\n\t\/\/ Set Timer 0 to check button press\r\n\tTCCR0A = _BV(WGM01);\r\n\tTCCR0B = _BV(CS00) | _BV(CS02);\r\n\tOCR0A = 100;\t\t\/\/ OCCR0A can be adjusted to change the button debounce time\r\n\tTIMSK0 = _BV(OCIE0A);\r\n\r\n\tsei();\t\/\/ Enable interrupts\r\n}\r\n\r\n\/\/ This will output the corresponding\r\n\/\/ &#039;number&#039; to digit 0 (left) or 1 (right)\r\nvoid display(int digit, int number)\r\n{\r\n\t\/\/cbi(PORTC, digit);\t\/\/ Ties display to ground\r\n\t\r\n\tif (digit == 0)\r\n\t\tsbi(PORTC, 0);\t\/\/ Ties display to ground\r\n\telse if (digit == 1)\r\n\t\tsbi(PORTC, 1);\r\n\t\r\n\tswitch(number)\t\/\/ Set PIND, display pins, to correct output\r\n\t{\r\n\t\tcase 0:\r\n\t\t\tPORTD = 0b11000000;\r\n\t\t\tbreak;\r\n\t\tcase 1:\r\n\t\t\tPORTD = 0b11111001;\r\n\t\t\tbreak;\r\n\t\tcase 2:\r\n\t\t\tPORTD = 0b10100100;\r\n\t\t\tbreak;\r\n\t\tcase 3:\r\n\t\t\tPORTD = 0b10110000;\r\n\t\t\tbreak;\r\n\t\tcase 4:\r\n\t\t\tPORTD = 0b10011001;\r\n\t\t\tbreak;\r\n\t\tcase 5:\r\n\t\t\tPORTD = 0b10010010;\r\n\t\t\tbreak;\r\n\t\tcase 6:\r\n\t\t\tPORTD = 0b10000010;\r\n\t\t\tbreak;\r\n\t\tcase 7:\r\n\t\t\tPORTD = 0b11111000;\r\n\t\t\tbreak;\r\n\t\tcase 8:\r\n\t\t\tPORTD = 0b10000000;\r\n\t\t\tbreak;\r\n\t\tcase 9:\r\n\t\t\tPORTD = 0b10010000;\r\n\t\t\tbreak;\r\n\t}\r\n\t\/\/ Turn decimal point on if above 100 &amp; 200\r\n\tif ((digit == 0) &amp;&amp; (speed &gt;= 200))\r\n\t\tcbi(PORTD, 7);\r\n\tif ((digit == 1) &amp;&amp; (speed &gt;= 100))\r\n\t\tcbi(PORTD, 7);\r\n}\r\n<\/pre>\n<p>&#8212;&#8212;<\/p>\n<p><strong>People can contact us:<\/strong> https:\/\/www.donluc.com\/?page_id=1927<\/p>\n<p><strong>Technology Experience<\/strong><\/p>\n<ul>\n<li>Programming Language<\/li>\n<li>Single-Board Microcontrollers (PIC, Arduino, Raspberry Pi,Espressif, etc&#8230;)<\/li>\n<li>IoT<\/li>\n<li>Wireless (Radio Frequency, Bluetooth, WiFi, Etc&#8230;)<\/li>\n<li>Robotics<\/li>\n<li>Camera and Video Capture Receiver Stationary, Wheel\/Tank and Underwater Vehicle<\/li>\n<li>Unmanned Vehicles Terrestrial and Marine<\/li>\n<li>Machine Learning<\/li>\n<li>RTOS<\/li>\n<li>Research &#038; Development (R &#038; D)<\/li>\n<\/ul>\n<p><strong>Instructor, E-Mentor, STEAM, and Arts-Based Training<\/strong><\/p>\n<ul>\n<li>Programming Language<\/li>\n<li>IoT<\/li>\n<li>PIC Microcontrollers<\/li>\n<li>Arduino<\/li>\n<li>Raspberry Pi<\/li>\n<li>Espressif<\/li>\n<li>Robotics<\/li>\n<\/ul>\n<p><strong>Follow Us<\/strong><\/p>\n<p><strong>Luc Paquin \u2013 Curriculum Vitae &#8211; 2023<\/strong><br \/>\nhttps:\/\/www.donluc.com\/luc\/<\/p>\n<p><strong>Web:<\/strong> https:\/\/www.donluc.com\/<br \/>\n<strong>Facebook:<\/strong> https:\/\/www.facebook.com\/neosteam.labs.9\/<br \/>\n<strong>YouTube:<\/strong> https:\/\/www.youtube.com\/@thesass2063<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\/neosteamlabs\/<\/p>\n<p><strong>Don Luc<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#8212;&#8212; #DonLucElectronics #DonLuc #Sound #Metronome #Project #Fritzing #Programming #Electronics #Microcontrollers #Consultant &#8212;&#8212; &#8212;&#8212; &#8212;&#8212; &#8212;&#8212; Metronome A metronome is a device that produces an audible click or other sound at a regular interval that can be set by the user, typically in Beats Per Minute (BPM). Metronomes may include synchronized visual motion. Musicians use the &#8230; <a title=\"Project #16: Sound &#8211; Metronome &#8211; Mk22\" class=\"read-more\" href=\"https:\/\/www.donluc.com\/?p=3372\" aria-label=\"Read more about Project #16: Sound &#8211; Metronome &#8211; Mk22\">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,271,49,38,59,5,272,10,43],"tags":[92,274,102,4,19,85,273,24,9,27,120,109,33,34],"class_list":["post-3372","post","type-post","status-publish","format-standard","hentry","category-sound","category-atmega168","category-consultant","category-digitalelectronics","category-fritzing","category-microcontrollers","category-program-c","category-projects","category-sparkfun","tag-battery","tag-c","tag-components","tag-consultant","tag-electronics","tag-fritzing","tag-metronome","tag-microcontroller","tag-programming","tag-projects-2","tag-sound","tag-sparkfun","tag-technology","tag-video-blog"],"_links":{"self":[{"href":"https:\/\/www.donluc.com\/index.php?rest_route=\/wp\/v2\/posts\/3372","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=3372"}],"version-history":[{"count":1,"href":"https:\/\/www.donluc.com\/index.php?rest_route=\/wp\/v2\/posts\/3372\/revisions"}],"predecessor-version":[{"id":3377,"href":"https:\/\/www.donluc.com\/index.php?rest_route=\/wp\/v2\/posts\/3372\/revisions\/3377"}],"wp:attachment":[{"href":"https:\/\/www.donluc.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3372"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.donluc.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3372"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.donluc.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3372"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}