{"id":2490,"date":"2020-11-06T07:32:42","date_gmt":"2020-11-06T15:32:42","guid":{"rendered":"http:\/\/www.donluc.com\/?p=2490"},"modified":"2020-11-06T07:32:42","modified_gmt":"2020-11-06T15:32:42","slug":"project-16-sound-tuning-mk07","status":"publish","type":"post","link":"https:\/\/www.donluc.com\/?p=2490","title":{"rendered":"Project #16: Sound &#8211; Tuning &#8211; Mk07"},"content":{"rendered":"<div style=\"width: 720px;\" class=\"wp-video\"><video class=\"wp-video-shortcode\" id=\"video-2490-1\" width=\"720\" height=\"406\" preload=\"metadata\" controls=\"controls\"><source type=\"video\/mp4\" src=\"https:\/\/www.donluc.com\/wp-content\/uploads\/2020\/11\/DL2011Mk01M.mp4?_=1\" \/><a href=\"https:\/\/www.donluc.com\/wp-content\/uploads\/2020\/11\/DL2011Mk01M.mp4\">https:\/\/www.donluc.com\/wp-content\/uploads\/2020\/11\/DL2011Mk01M.mp4<\/a><\/video><\/div>\n<p>&#8212;&#8212;<\/p>\n<p>#donluc #sound #simplekeyboard #synthesizer #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\/11\/DL2011Mk02a.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.donluc.com\/wp-content\/uploads\/2020\/11\/DL2011Mk02a.png\" alt=\"Tuning\" width=\"720\" height=\"493\" class=\"alignnone size-full wp-image-2492\" srcset=\"https:\/\/www.donluc.com\/wp-content\/uploads\/2020\/11\/DL2011Mk02a.png 720w, https:\/\/www.donluc.com\/wp-content\/uploads\/2020\/11\/DL2011Mk02a-300x205.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\/11\/DL2011Mk02b.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.donluc.com\/wp-content\/uploads\/2020\/11\/DL2011Mk02b.png\" alt=\"Tuning\" width=\"720\" height=\"480\" class=\"alignnone size-full wp-image-2493\" srcset=\"https:\/\/www.donluc.com\/wp-content\/uploads\/2020\/11\/DL2011Mk02b.png 720w, https:\/\/www.donluc.com\/wp-content\/uploads\/2020\/11\/DL2011Mk02b-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\/11\/DL2011Mk02c.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.donluc.com\/wp-content\/uploads\/2020\/11\/DL2011Mk02c.png\" alt=\"Tuning\" width=\"720\" height=\"480\" class=\"alignnone size-full wp-image-2494\" srcset=\"https:\/\/www.donluc.com\/wp-content\/uploads\/2020\/11\/DL2011Mk02c.png 720w, https:\/\/www.donluc.com\/wp-content\/uploads\/2020\/11\/DL2011Mk02c-300x200.png 300w\" sizes=\"auto, (max-width: 720px) 100vw, 720px\" \/><\/a><\/p>\n<p>&#8212;&#8212;<\/p>\n<p><strong>Tuning<\/strong><\/p>\n<p>Frequencies for equal-tempered scale. The pitches the frequencies of the twelve notes between note A, and note A one octave up from it. Higher pitched notes have larger frequency steps between them, but each step makes an equal change to difference in pitch (one semitone) that we perceive. The piano keyboard is one of the classic ways of viewing the Chromatic scale. Also, the whole pattern of note names repeats after every seven white notes.<\/p>\n<p>There are two main properties of a regular vibration, the amplitude and the frequency, which affect the way it sounds. Amplitude is the size of the vibration, and this determines how loud the sound is. We have already seen that larger vibrations make a louder sound. It is also the origin of the word amplifier, a device which increases the amplitude of a waveform. Frequency is the speed of the vibration, and this determines the pitch of the sound. It is only useful or meaningful for musical sounds, where there is a strongly regular waveform.<\/p>\n<p><strong>Arduino<\/strong><\/p>\n<p>This simple keyboard how to use the to generate different pitches depending on which button is pressed. A potentiometer is a simple mechanical device that provides a varying amount of resistance when its shaft is turned. By passing voltage through a potentiometer and into an analog input on your board, it is possible to measure the amount of resistance produced by a potentiometer as an analog value. Re-maps a number from one range to another. That is, a value of from Low would get mapped to Low, a value of from High to High. Range Frequency Note Low => Note High. Read the state of the pushbutton value, Low a frequency of High.<\/p>\n<p><strong>DL2011Mk01<\/strong><\/p>\n<p>1 x Arduino Pro Mini 328 &#8211; 5V\/16MHz<br \/>\n8 x Tactile Button<br \/>\n1 x 1K Potentiometer<br \/>\n1 x Knob<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 \/>\n5 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\/16MH<\/strong>z<\/p>\n<p>SPK &#8211; Digital 11<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 \/>\nPO1 &#8211; Analog A0<br \/>\nVIN &#8211; +5V<br \/>\nGND &#8211; GND<\/p>\n<p><strong>DL2011Mk01p.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 - Tuning - Mk07\r\n\/\/ 11-01\r\n\/\/ DL2011Mk01p.ino 16-07\r\n\/\/ 1 x Arduino Pro Mini 328 - 5V\/16MHz\r\n\/\/ 8 x Tactile Button\r\n\/\/ 1 x 1K Potentiometer\r\n\/\/ 1 x Knob\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\/\/ 5 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\/\/ Pitches\r\n#include \"pitches.h\"\r\n\/\/ Waveform - Chimes\r\n#include \"chimes.h\"\r\nusing namespace Chimes;\r\n\/\/ Sum of ADSR values must not exceed 100%\r\nuint8_t envelope[] = {\r\n  0,  \/\/ Attack[%]\r\n  20, \/\/ Decay[%]\r\n  0,  \/\/ Sustain[%]\r\n  80, \/\/ Release[%]\r\n  16  \/\/ Sustain Level 1..32\r\n};\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\/\/ Frequency\r\nint iCap = A0;\r\nint iFreg = 0;\r\nint iNoteA = 0;\r\nint iNoteB = 0;\r\nint iNoteC = 0;\r\nint iNoteD = 0;\r\nint iNoteE = 0;\r\nint iNoteF = 0;\r\nint iNoteG = 0;\r\nint iNoteAA = 0;\r\n\r\n\/\/ Software Version Information\r\nString sver = \"16-07\";\r\n\r\nvoid loop() {\r\n\r\n  \/\/ Frequency\r\n  isPitches();\r\n  \r\n  \/\/ Keyboard\r\n  isKeyboard();\r\n  \r\n}\r\n<\/pre>\n<p><strong>chimes.cpp<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">\r\n\/*This work is licensed under the Creative Commons Attribution-ShareAlike 4.0 International License. \r\nTo view a copy of this license, visit https:\/\/creativecommons.org\/licenses\/by-sa\/4.0\/deed.en *\/\r\n\r\n#include <Math.h>\r\n#include \"chimes.h\"\r\n\r\n#define ISR_CYCLE 16 \/\/16s\r\n\r\nchar strbuf[255];\r\nuint16_t ADSR_default[] = {0, 0, 100, 0, MAX_VOLUME};\r\nuint16_t ADSR_env[5];\r\nuint16_t nSamples; \/\/Number of samples in Array\r\nuint8_t adsrPhase;\r\nuint32_t tPeriod;\r\nuint8_t *samples; \/\/Array with samples\r\nuint8_t *_envelope, _waveform, _duty_cycle;\r\nuint16_t &_sustain_lvl = ADSR_env[4];\r\n\r\nenum ADSR_phase\r\n{\r\n\tATTACK,\r\n\tDECAY,\r\n\tSUSTAIN,\r\n\tRELEASE\r\n};\r\n\r\nnamespace Chimes\r\n{\r\nvoid init(uint8_t waveform, uint8_t duty_cycle, uint8_t *envelope)\r\n{\r\n\tSerial.begin(115200);\r\n\t\/\/PWM Signal generation\r\n\tDDRB |= (1 << PB3) + (1 << PB0);\t\t\t\t  \/\/OC2A, Pin 11\r\n\tTCCR2A = (1 << WGM21) + (1 << WGM20);\t\t\t  \/\/Fast PWM\r\n\tTCCR2A |= (0 << COM2A0) + (1 << COM2A1);\t\t  \/\/Set OC2A on compare match, clear OC2A at BOTTOM,(inverting mode).\r\n\tTCCR2B = (0 << CS22) + (0 << CS21) + (1 << CS20); \/\/No Prescaling\r\n\tsamples = (uint8_t *)malloc(0);\r\n\t_waveform = waveform;\r\n\t_duty_cycle = duty_cycle;\r\n\t_envelope = envelope;\r\n}\r\n\r\nvoid play(uint16_t freq, uint16_t duration)\r\n{\r\n\tuint8_t waveform = _waveform;\r\n\t\/\/Init adsr according to the length of the note\r\n\tfor (int i = 0; i < 4; i++)\r\n\t{\r\n\t\tif (_envelope)\r\n\t\t{\r\n\t\t\tADSR_env[i] = (uint32_t)_envelope[i] * duration \/ 100;\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tADSR_env[i] = (uint32_t)ADSR_default[i] * duration \/ 100;\r\n\t\t}\r\n\t\t\/\/Serial.println(ADSR_env[i]);\r\n\t}\r\n\tADSR_env[4] = _envelope ? _envelope[4] : MAX_VOLUME;\r\n\t\/\/Serial.println(ADSR_env[4]);\r\n\r\n\tif (freq == 0)\r\n\t{ \/\/Pause\r\n\t\ttPeriod = ISR_CYCLE * 100;\r\n\t\twaveform = PAUSE;\r\n\t}\r\n\telse\r\n\t\ttPeriod = 1E6 \/ freq;\r\n\r\n\tnSamples = tPeriod \/ ISR_CYCLE;\r\n\trealloc(samples, nSamples);\r\n\tuint16_t nDuty = (_duty_cycle * nSamples) \/ 100;\r\n\r\n\tswitch (waveform)\r\n\t{\r\n\tcase SINE: \/\/Sinewave\r\n\t\tfor (int i = 0; i < nSamples; i++)\r\n\t\t{\r\n\t\t\tsamples[i] = 128 + 127 * sin(2 * PI * i \/ nSamples);\r\n\t\t}\r\n\t\tbreak;\r\n\r\n\tcase TRI: \/\/Triangle\r\n\t\tfor (int16_t i = 0; i < nSamples; i++)\r\n\t\t{\r\n\t\t\tif (i < nDuty)\r\n\t\t\t{\r\n\t\t\t\tsamples[i] = 255 * (double)i \/ nDuty; \/\/Rise\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tsamples[i] = 255 * (1 - (double)(i - nDuty) \/ (nSamples - nDuty)); \/\/Fall\r\n\t\t\t}\r\n\t\t}\r\n\t\tbreak;\r\n\tcase RECT: \/\/Rectangle\r\n\t\tfor (int16_t i = 0; i < nSamples; i++)\r\n\t\t{\r\n\t\t\ti < nDuty ? samples[i] = 255 : samples[i] = 0;\r\n\t\t}\r\n\t\tbreak;\r\n\tcase PAUSE: \/\/Rectangle\r\n\t\tmemset(samples, 0, nSamples);\r\n\t}\r\n\tTIMSK2 = (1 << TOIE2);\r\n\t\/*for(uint16_t i = 0; i < nSamples; i++) {\r\n\t\tsprintf(strbuf, \"%d: %d\", i, samples[i]);\r\n\t\tSerial.println(strbuf);\r\n\t}*\/\r\n}\r\n\r\n\/\/Returns true, while note is playing\r\nboolean isPlaying()\r\n{\r\n\treturn (1 << TOIE2) &#038; TIMSK2;\r\n}\r\n} \/\/ namespace Chimes\r\n\r\n\/\/Called every 16s, when TIMER1 overflows\r\nISR(TIMER2_OVF_vect)\r\n{\r\n\tstatic uint32_t adsr_timer, adsr_time;\r\n\tstatic uint16_t cnt; \/\/Index counter\r\n\tstatic uint8_t sustain_lvl, vol;\r\n\r\n\t\/\/Set OCR2A to the next value in sample array, this will change the duty cycle accordingly\r\n\tOCR2A = vol * samples[cnt] \/ MAX_VOLUME;\r\n\tif (cnt < nSamples - 1)\r\n\t{\r\n\t\tcnt++;\r\n\t}\r\n\telse\r\n\t{\r\n\t\tcnt = 0;\r\n\t\tadsr_timer += tPeriod;\r\n\t\tif (adsr_timer >= 10000)\r\n\t\t{ \/\/every 10 millisecond\r\n\t\t\tadsr_timer = 0;\r\n\r\n\t\t\tswitch (adsrPhase)\r\n\t\t\t{\r\n\t\t\tcase ATTACK:\r\n\t\t\t\tif (ADSR_env[ATTACK])\r\n\t\t\t\t{\r\n\t\t\t\t\tvol = MAX_VOLUME * (float)adsr_time \/ ADSR_env[ATTACK];\r\n\t\t\t\t\tif (vol == MAX_VOLUME)\r\n\t\t\t\t\t{ \/\/Attack phase over\r\n\t\t\t\t\t\tadsrPhase = DECAY;\r\n\t\t\t\t\t\tadsr_time = 0;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tadsrPhase = DECAY;\r\n\t\t\t\t\tvol = MAX_VOLUME;\r\n\t\t\t\t\tadsr_time = 0;\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase DECAY:\r\n\t\t\t\tif (ADSR_env[DECAY])\r\n\t\t\t\t{\r\n\t\t\t\t\tsustain_lvl = _sustain_lvl;\r\n\t\t\t\t\tvol = MAX_VOLUME - (MAX_VOLUME - _sustain_lvl) * (float)adsr_time \/ ADSR_env[DECAY];\r\n\t\t\t\t\tif (vol <= sustain_lvl)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tadsr_time = 0;\r\n\t\t\t\t\t\tadsrPhase = SUSTAIN;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tadsrPhase = SUSTAIN;\r\n\t\t\t\t\tsustain_lvl = MAX_VOLUME;\r\n\t\t\t\t\tadsr_time = 0;\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase SUSTAIN:\r\n\t\t\t\tif (adsr_time > ADSR_env[SUSTAIN])\r\n\t\t\t\t{\r\n\t\t\t\t\tadsrPhase = RELEASE;\r\n\t\t\t\t\tadsr_time = 0;\r\n\t\t\t\t}\r\n\r\n\t\t\t\tbreak;\r\n\t\t\tcase RELEASE:\r\n\t\t\t\tif (ADSR_env[RELEASE])\r\n\t\t\t\t{\r\n\t\t\t\t\tvol = sustain_lvl * (1 - (float)adsr_time \/ ADSR_env[RELEASE]);\r\n\t\t\t\t\tif (vol == 0)\r\n\t\t\t\t\t{ \/\/Attack phase over\r\n\t\t\t\t\t\tadsr_time = 0;\r\n\t\t\t\t\t\tTIMSK2 = (0 << TOIE2);\r\n\t\t\t\t\t\tadsrPhase = ATTACK;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tadsrPhase = ATTACK;\r\n\t\t\t\t\tvol = 0;\r\n\t\t\t\t\tadsr_time = 0;\r\n\t\t\t\t\tTIMSK2 = (0 << TOIE2);\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\tadsr_time += 10;\r\n\t\t}\r\n\t}\r\n}\r\n<\/pre>\n<p><strong>chimes.h<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">\r\n\/*This work is licensed under the Creative Commons Attribution-ShareAlike 4.0 International License. \r\nTo view a copy of this license, visit https:\/\/creativecommons.org\/licenses\/by-sa\/4.0\/deed.en *\/\r\n\r\n#ifndef CHIMES_H\r\n#define CHIMES_H\r\n#include \"Arduino.h\"\r\n\r\nenum waveform\r\n{\r\n\tSINE, \/\/Sinus\r\n\tRECT, \/\/Triangle\r\n\tTRI,  \/\/Rectangle\r\n\tPAUSE \/\/Internal, do not use\r\n};\r\n#define MAX_VOLUME 32\r\n\r\nnamespace Chimes\r\n{\r\nvoid init(uint8_t waveform = SINE, uint8_t duty_cycle = 50, uint8_t *envelope = NULL);\r\nvoid play(uint16_t freq, uint16_t duration);\r\n\r\n\/\/Returns true while note is playing\r\nboolean isPlaying();\r\n} \/\/ namespace Chimes\r\n\r\n#endif\r\n<\/pre>\n<p><strong>getKeyboard.ino<\/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    \/\/ Waveform\r\n    isPlaying();\r\n    play(iNoteA, 1000);\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    \/\/ Waveform\r\n    isPlaying();\r\n    play(iNoteB, 1000);\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    \/\/ Waveform\r\n    isPlaying();\r\n    play(iNoteC, 1000);\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    \/\/ Waveform\r\n    isPlaying();\r\n    play(iNoteD, 1000);\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    \/\/ Waveform\r\n    isPlaying();\r\n    play(iNoteE, 1000);\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    \/\/ Waveform\r\n    isPlaying();\r\n    play(iNoteF, 1000);\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    \/\/ Waveform\r\n    isPlaying();\r\n    play(iNoteG, 1000);\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    \/\/ Waveform\r\n    isPlaying();\r\n    play(iNoteAA, 1000);\r\n    \r\n  }\r\n  else\r\n  {\r\n    \r\n    hh = hh - 1;\r\n    \r\n  }\r\n\r\n  \/\/ Waveform\r\n  isPlaying();\r\n  play(0, 50);\r\n\r\n}\r\n<\/pre>\n<p><strong>getPitches.ino<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">\r\n\/\/ Pitches\r\n\/\/ isPitches\r\nvoid isPitches(){\r\n  \r\n  \/\/ Frequency\r\n  iFreg = analogRead(iCap);\r\n  iFreg = map(iFreg, 0, 1023, 1, 6);\r\n\r\n  \/\/ Range Frequency Note Low => High\r\n  switch ( iFreg ) {\r\n    case 1:\r\n      \/\/ NOTE A1\r\n      iNoteA = NOTE_A1;\r\n      iNoteB = NOTE_B1;\r\n      iNoteC = NOTE_C2;\r\n      iNoteD = NOTE_D2;\r\n      iNoteE = NOTE_E2;\r\n      iNoteF = NOTE_F2;\r\n      iNoteG = NOTE_G2;\r\n      iNoteAA = NOTE_A2;\r\n      break;\r\n    case 2:\r\n      \/\/ NOTE A2\r\n      iNoteA = NOTE_A2;\r\n      iNoteB = NOTE_B2;\r\n      iNoteC = NOTE_C3;\r\n      iNoteD = NOTE_D3;\r\n      iNoteE = NOTE_E3;\r\n      iNoteF = NOTE_F3;\r\n      iNoteG = NOTE_G3;\r\n      iNoteAA = NOTE_A3;\r\n      break;\r\n    case 3:\r\n      \/\/ NOTE A3\r\n      iNoteA = NOTE_A3;\r\n      iNoteB = NOTE_B3;\r\n      iNoteC = NOTE_C4;\r\n      iNoteD = NOTE_D4;\r\n      iNoteE = NOTE_E4;\r\n      iNoteF = NOTE_F4;\r\n      iNoteG = NOTE_G4;\r\n      iNoteAA = NOTE_A4;\r\n      break;\r\n    case 4:\r\n      \/\/ NOTE A4\r\n      iNoteA = NOTE_A4;\r\n      iNoteB = NOTE_B4;\r\n      iNoteC = NOTE_C5;\r\n      iNoteD = NOTE_D5;\r\n      iNoteE = NOTE_E5;\r\n      iNoteF = NOTE_F5;\r\n      iNoteG = NOTE_G5;\r\n      iNoteAA = NOTE_A5;\r\n      break;\r\n    case 5:\r\n      \/\/ NOTE A5\r\n      iNoteA = NOTE_A5;\r\n      iNoteB = NOTE_B5;\r\n      iNoteC = NOTE_C6;\r\n      iNoteD = NOTE_D6;\r\n      iNoteE = NOTE_E6;\r\n      iNoteF = NOTE_F6;\r\n      iNoteG = NOTE_G6;\r\n      iNoteAA = NOTE_A6;\r\n      break;\r\n    case 6:\r\n      \/\/ NOTE A6\r\n      iNoteA = NOTE_A6;\r\n      iNoteB = NOTE_B6;\r\n      iNoteC = NOTE_C7;\r\n      iNoteD = NOTE_D7;\r\n      iNoteE = NOTE_E7;\r\n      iNoteF = NOTE_F7;\r\n      iNoteG = NOTE_G7;\r\n      iNoteAA = NOTE_A7;\r\n      break;\r\n  }\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  \/\/ Waveform\r\n  init(\r\n\r\n    \/\/ SINE, TRI and RECT\r\n    SINE,\r\n    \/\/ Duty cycle 0..100%, only matters for Triangle and Rectangle \r\n    50,\r\n    \/\/ Envelope\r\n  envelope);\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...)<\/li>\n<li>Robotics<\/li>\n<li>Research & Development (R & D)<\/li>\n<li>Desktop Applications (Windows, OSX, Linux, Multi-OS, Multi-Tier, etc...)<\/li>\n<li>Mobile Applications (Android, iOS, Blackberry, Windows Mobile, Windows CE, etc...)<\/li>\n<li>Web Applications (LAMP, Scripting, Java, ASP, ASP.NET, RoR, Wakanda, etc...)<\/li>\n<li>Social Media Programming & Integration (Facebook, Twitter, YouTube, Pinterest, etc...)<\/li>\n<li>Content Management Systems (WordPress, Drupal, Joomla, Moodle, etc...)<\/li>\n<li>Bulletin Boards (phpBB, SMF, Vanilla, jobberBase, etc...)<\/li>\n<li>eCommerce (WooCommerce, OSCommerce, ZenCart, PayPal Shopping Cart, etc...)<\/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 #simplekeyboard #synthesizer #programming #arduino #fritzing #electronics #microcontrollers #consultant #vlog &#8212;&#8212; &#8212;&#8212; &#8212;&#8212; &#8212;&#8212; Tuning Frequencies for equal-tempered scale. The pitches the frequencies of the twelve notes between note A, and note A one octave up from it. Higher pitched notes have larger frequency steps between them, but each step makes an equal &#8230; <a title=\"Project #16: Sound &#8211; Tuning &#8211; Mk07\" class=\"read-more\" href=\"https:\/\/www.donluc.com\/?p=2490\" aria-label=\"Read more about Project #16: Sound &#8211; Tuning &#8211; Mk07\">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,120,109,8,33,126,34,108],"class_list":["post-2490","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-sound","tag-sparkfun","tag-synth","tag-technology","tag-tuning","tag-video-blog","tag-vlog"],"_links":{"self":[{"href":"https:\/\/www.donluc.com\/index.php?rest_route=\/wp\/v2\/posts\/2490","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=2490"}],"version-history":[{"count":1,"href":"https:\/\/www.donluc.com\/index.php?rest_route=\/wp\/v2\/posts\/2490\/revisions"}],"predecessor-version":[{"id":2495,"href":"https:\/\/www.donluc.com\/index.php?rest_route=\/wp\/v2\/posts\/2490\/revisions\/2495"}],"wp:attachment":[{"href":"https:\/\/www.donluc.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2490"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.donluc.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2490"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.donluc.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2490"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}