├── README.md ├── V1 └── Digital_Handpan_Poly_Touch_Sense │ ├── note_frequency.h │ ├── scales.h │ ├── TeensyAudioDesignTool.h │ └── Digital_Handpan_Poly_Touch_Sense.ino ├── LICENSE.md └── V2 └── Digital_Handpan_V2 ├── note_frequency.h ├── TeensyAudioDesignTool.h └── Digital_Handpan_V2.ino /README.md: -------------------------------------------------------------------------------- 1 | Digital Handpan 2 | ======================================== 3 | 4 | [![Digital Handpan V2](https://cdn.sparkfun.com/r/500-500/assets/home_page_posts/2/6/2/3/Digital_Handpan_V2-09.jpg)](https://cdn.sparkfun.com/assets/home_page_posts/2/6/2/3/Digital_Handpan_V2-09.jpg) 5 | 6 | Code for the Digital Handpan - A project using capacitive touch on the Teensy in conjunction with the Teensy Audio Shield. 7 | 8 | Repository Contents 9 | ------------------- 10 | * **/V2** - V2 example code with enclosure 11 | * **/V1** - V1 example code for the prototype 12 | 13 | Documentation 14 | -------------- 15 | 16 | * [Digital Handpan V2: The Touch Drum](https://www.sparkfun.com/news/2623) 17 | * [Enginursday: Digital Handpan](https://www.sparkfun.com/news/2222) 18 | 19 | License Information 20 | ------------------- 21 | 22 | This product is _**open source**_! 23 | 24 | Please review the LICENSE.md file for license information. 25 | 26 | If you have any questions or concerns on licensing, please contact techsupport@sparkfun.com. 27 | 28 | Distributed as-is; no warranty is given. 29 | 30 | - Your friends at SparkFun. 31 | 32 | __ 33 | -------------------------------------------------------------------------------- /V1/Digital_Handpan_Poly_Touch_Sense/note_frequency.h: -------------------------------------------------------------------------------- 1 | //This is a note table containing all the notes for each octave and their corresponding frequencies 2 | 3 | float note_frequency[128] = { 4 | 8.17579, //C-1 0 5 | 8.66195, 6 | 9.17702, 7 | 9.72271, 8 | 10.3008, 9 | 10.9133, 10 | 11.5623, 11 | 12.2498, 12 | 12.9782, 13 | 13.7500, 14 | 14.5676, 15 | 15.4338, 16 | 17 | 16.3515, //C0 12 18 | 17.3239, //C#0.Db0 19 | 18.3540, //D0 20 | 19.4454, //D#.Eb0 21 | 20.6017, //E0 22 | 21.8267, //F0 23 | 23.1246, //F#0.Gb0 24 | 24.4997, //G0 25 | 25.9565, //G#0.Ab0 26 | 27.5000, //A0 27 | 29.1352, //A#0.Bb0 28 | 30.8677, //B0 29 | 30 | 32.7031, //C1 24 31 | 34.6478, 32 | 36.7080, 33 | 38.8908, 34 | 41.2034, 35 | 43.6535, 36 | 46.2493, 37 | 48.9994, 38 | 51.9130, 39 | 55.0000, 40 | 58.2704, 41 | 61.7354, 42 | 43 | 65.4063, //C2 36 44 | 69.2956, 45 | 73.4161, 46 | 77.7817, 47 | 82.4068, 48 | 87.3070, 49 | 92.4986, 50 | 97.9988, 51 | 103.826, 52 | 110.000, 53 | 116.540, 54 | 123.470, 55 | 56 | 130.812, //C3 48 57 | 138.591, 58 | 146.832, 59 | 155.563, 60 | 164.813, 61 | 174.614, 62 | 184.997, 63 | 195.997, 64 | 207.652, 65 | 220.000, 66 | 233.081, 67 | 246.941, 68 | 69 | 261.625, //C4 60 70 | 277.182, 71 | 293.664, 72 | 311.126, 73 | 329.627, 74 | 349.228, 75 | 369.994, 76 | 391.995, 77 | 415.304, 78 | 440.000, 79 | 466.163, 80 | 493.883, 81 | 82 | 523.251, //C5 72 83 | 554.365, 84 | 587.329, 85 | 622.253, 86 | 659.255, 87 | 698.456, 88 | 739.988, 89 | 783.990, 90 | 830.609, 91 | 880.000, 92 | 932.327, 93 | 987.766, 94 | 95 | 1046.50, //C6 84 96 | 1108.73, 97 | 1174.65, 98 | 1244.50, 99 | 1318.51, 100 | 1396.91, 101 | 1479.97, 102 | 1567.98, 103 | 1661.21, 104 | 1760.00, 105 | 1864.65, 106 | 1975.53, 107 | 108 | 2093.00, //C7 96 109 | 2217.46, 110 | 2349.31, 111 | 2489.01, 112 | 2637.02, 113 | 2793.82, 114 | 2959.95, 115 | 3135.96, 116 | 3322.43, 117 | 3520.00, 118 | 3729.31, 119 | 3951.06, 120 | 121 | 4186.00, //C8 108 122 | 4434.92, 123 | 4698.63, 124 | 4978.03, 125 | 5274.04, 126 | 5587.65, 127 | 5919.91, 128 | 6271.92, 129 | 6644.87, 130 | 7040.00, 131 | 7458.62, 132 | 7902.13, 133 | 134 | 8372.01, //C9 120 135 | 8869.84, 136 | 9397.27, 137 | 9956.06, 138 | 10548.0, 139 | 11175.3, 140 | 11839.8, 141 | 12543.8 142 | }; 143 | 144 | 145 | 146 | 147 | 148 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | SparkFun License Information 2 | ============================ 3 | 4 | SparkFun uses two different licenses for our files — one for hardware and one for code. 5 | 6 | Hardware 7 | --------- 8 | 9 | **SparkFun hardware is released under [Creative Commons Share-alike 4.0 International](http://creativecommons.org/licenses/by-sa/4.0/).** 10 | 11 | Note: This is a human-readable summary of (and not a substitute for) the [license](http://creativecommons.org/licenses/by-sa/4.0/legalcode). 12 | 13 | You are free to: 14 | 15 | Share — copy and redistribute the material in any medium or format 16 | Adapt — remix, transform, and build upon the material 17 | for any purpose, even commercially. 18 | The licensor cannot revoke these freedoms as long as you follow the license terms. 19 | Under the following terms: 20 | 21 | Attribution — You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use. 22 | ShareAlike — If you remix, transform, or build upon the material, you must distribute your contributions under the same license as the original. 23 | No additional restrictions — You may not apply legal terms or technological measures that legally restrict others from doing anything the license permits. 24 | Notices: 25 | 26 | You do not have to comply with the license for elements of the material in the public domain or where your use is permitted by an applicable exception or limitation. 27 | No warranties are given. The license may not give you all of the permissions necessary for your intended use. For example, other rights such as publicity, privacy, or moral rights may limit how you use the material. 28 | 29 | 30 | Code 31 | -------- 32 | 33 | **SparkFun code, firmware, and software is released under the MIT License(http://opensource.org/licenses/MIT).** 34 | 35 | The MIT License (MIT) 36 | 37 | Copyright (c) 2016 SparkFun Electronics 38 | 39 | Permission is hereby granted, free of charge, to any person obtaining a copy 40 | of this software and associated documentation files (the "Software"), to deal 41 | in the Software without restriction, including without limitation the rights 42 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 43 | copies of the Software, and to permit persons to whom the Software is 44 | furnished to do so, subject to the following conditions: 45 | 46 | The above copyright notice and this permission notice shall be included in all 47 | copies or substantial portions of the Software. 48 | 49 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 50 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 51 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 52 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 53 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 54 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 55 | SOFTWARE. 56 | -------------------------------------------------------------------------------- /V1/Digital_Handpan_Poly_Touch_Sense/scales.h: -------------------------------------------------------------------------------- 1 | //This file contains the various Scales used by the digital handpan. 2 | //Each number corresponds to a position in the note_frequency.h table 3 | //Many of these scales were imported using this site as a reference: 4 | //https://hapidrum.co/hapi-drum-scale.aspx 5 | 6 | ///CHANGE WHEN ADDING NEW SCALES 7 | int numOfScales = 6;//7-1=6 8 | 9 | int scale[][8] = 10 | { 11 | //G Major (G3, A3, B3, D4, E4, G4, A4, B4) scale [0][x] x=0-7 12 | { 13 | 55,//196.00,//G3 14 | 57,//220,//A3 15 | 59,//246.94,//B3 16 | 62,//293.66,//D4 17 | 64,//329.63,//E4 18 | 67,//392,//G4 19 | 69,//440,//A4 20 | 71//493.88,//B4 21 | }, 22 | ///////////////////////////////////////////////////// 23 | //G Minor (G3, Bb3, C4, D4, F4, G4, Bb4, C5) 24 | { 25 | 55,//196.00,//G3 26 | 58,//(233.88);//Bb3 27 | 60,//(261.63);//C4 (Middle C) 28 | 62,//293.66,//D4 29 | 65,//(174.61);//F4 30 | 67,//392,//G4 31 | 70,//(233.88);//Bb4 32 | 72//(523.25);//C5 33 | }, 34 | ///////////////////////////////////////////////////// 35 | //C Major (C4, D4, E4, G4, A4, C5, D5, E5) 36 | { 37 | 60,//(261.63);//C4 (Middle C) 38 | 62,//293.66,//D4 39 | 64,//329.63,//E4 40 | 67,//392,//G4 41 | 69,//440,//A4 42 | 72,//(523.25);//C5 43 | 74,//(587.32);//D5 44 | 76//(659.26);//E5 45 | }, 46 | ///////////////////////////////////////////////////// 47 | //D Akebono (D4, E4, F4, A4, Bb4, D5, E5, F5) 48 | { 49 | 62,//(146.83);//D4 50 | 64,//(164.81);//E4 51 | 65,//(174.61);//F4 52 | 69,//220,//A4 53 | 70,//(233.88);//Bb4 54 | 74,//293.66,//D5 55 | 76,//329.63,//E5 56 | 77//(349.23);//F5 57 | /* 58 | 50,//(146.83);//D3 59 | 52,//(164.81);//E3 60 | 53,//(174.61);//F3 61 | 57,//220,//A3 62 | 58,//(233.88);//Bb3 63 | 62,//293.66,//D4 64 | 64,//329.63,//E4 65 | 65//(349.23);//F4 66 | */ 67 | }, 68 | ///////////////////////////////////////////////////// 69 | //D Major (D4, E4, F#4, A4, B4, D5, E5, F#5) 70 | { 71 | 62,//(146.83);//D4 72 | 64,//(164.81);//E4 73 | 66,//F#4 74 | 69,//220,//A4 75 | 71,//B4 76 | 74,//293.66,//D5 77 | 76,//329.63,//E5 78 | 78//F#5 79 | }, 80 | ///////////////////////////////////////////////////// 81 | //A Minor (A3, C4, D4, E4, G4, A4, C5, D5) 82 | { 83 | 57,//A3 84 | 60,//C4 85 | 62,//(146.83);//D4 86 | 64,//(164.81);//E4 87 | 67,//392,//G4 88 | 69,//220,//A4 89 | 72,//C5 90 | 74//293.66,//D5 91 | }, 92 | ///////////////////////////////////////////////////// 93 | //A Akebono (A3, B3, C4, E4, F4, A4, B4, C5) 94 | { 95 | 57,//A3 96 | 59,//246.94,//B3 97 | 60,//C4 98 | 64,//(164.81);//E4 99 | 65,//(174.61);//F4 100 | 69,//A4 101 | 71,//B4 102 | 72//C5 103 | } 104 | ///////////////////////////////////////////////////// 105 | }; 106 | 107 | -------------------------------------------------------------------------------- /V2/Digital_Handpan_V2/note_frequency.h: -------------------------------------------------------------------------------- 1 | //This is a note table containing all the notes for each octave and their corresponding frequencies 2 | 3 | float note_frequency[128] = { 4 | 8.17579, //C-1 0 5 | 8.66195, 6 | 9.17702, 7 | 9.72271, 8 | 10.3008, 9 | 10.9133, 10 | 11.5623, 11 | 12.2498, 12 | 12.9782, 13 | 13.7500, 14 | 14.5676, 15 | 15.4338, 16 | 17 | 16.3515, //C0 12 18 | 17.3239, //C#0.Db0 19 | 18.3540, //D0 20 | 19.4454, //D#.Eb0 21 | 20.6017, //E0 22 | 21.8267, //F0 23 | 23.1246, //F#0.Gb0 24 | 24.4997, //G0 25 | 25.9565, //G#0.Ab0 26 | 27.5000, //A0 27 | 29.1352, //A#0.Bb0 28 | 30.8677, //B0 29 | 30 | 32.7031, //C1 24 31 | 34.6478, //C#0.Db0 32 | 36.7080, 33 | 38.8908, 34 | 41.2034, 35 | 43.6535, 36 | 46.2493, 37 | 48.9994, 38 | 51.9130, 39 | 55.0000, 40 | 58.2704, 41 | 61.7354, 42 | 43 | 65.4063, //C2 36 44 | 69.2956, //C#0.Db0 45 | 73.4161, 46 | 77.7817, 47 | 82.4068, 48 | 87.3070, 49 | 92.4986, 50 | 97.9988, 51 | 103.826, 52 | 110.000, 53 | 116.540, 54 | 123.470, 55 | 56 | 130.812, //C3 48 57 | 138.591, //C#3.Db3 49 58 | 146.832, //D3 50 59 | 155.563, //D#3.Eb3 51 60 | 164.813, //E 52 61 | 174.614, //F 53 62 | 184.997, //F#.Gb 54 63 | 195.997, //G 55 64 | 207.652, //G#.Ab 56 65 | 220.000, //A 57 66 | 233.081, //A#.Bb 58 67 | 246.941, //B 59 68 | 69 | 261.625, //C4 60 MIDDLE C 70 | 277.182, //C#4.Db4 61 71 | 293.664, //D4 62 72 | 311.126, //D#4.Eb4 63 73 | 329.627, //E 64 74 | 349.228, //F 65 75 | 369.994, //F#,Gb 66 76 | 391.995, //G 67 77 | 415.304, //G#, Ab 68 78 | 440.000, //A 69 79 | 466.163, //A#, Bb 70 80 | 493.883, //B 71 81 | 82 | 523.251, //C5 72 83 | 554.365, //C#0.Db0 73 84 | 587.329, //D 74 85 | 622.253, //D#, Eb 75 86 | 659.255, //E 76 87 | 698.456, //F 77 88 | 739.988, //F#,Gb 78 89 | 783.990, //G5 79 90 | 830.609, //G#,Ab 80 91 | 880.000, //A 81 92 | 932.327, //A#,Bb 82 93 | 987.766, //B 83 94 | 95 | 1046.50, //C6 84 96 | 1108.73, //C#0.Db0 85 97 | 1174.65, //D 86 98 | 1244.50, //D#,Eb 87 99 | 1318.51, //E 88 100 | 1396.91, //F 89 101 | 1479.97, //F#,Gb 90 102 | 1567.98, //G6 91 103 | 1661.21, //G#,Ab 92 104 | 1760.00, //A 93 105 | 1864.65, //A#,Bb 94 106 | 1975.53, //B 95 107 | 108 | 2093.00, //C7 96 109 | 2217.46, //C#0.Db0 110 | 2349.31, 111 | 2489.01, 112 | 2637.02, 113 | 2793.82, 114 | 2959.95, 115 | 3135.96, 116 | 3322.43, 117 | 3520.00, 118 | 3729.31, 119 | 3951.06, 120 | 121 | 4186.00, //C8 108 122 | 4434.92, //C#0.Db0 123 | 4698.63, 124 | 4978.03, 125 | 5274.04, 126 | 5587.65, 127 | 5919.91, 128 | 6271.92, 129 | 6644.87, 130 | 7040.00, 131 | 7458.62, 132 | 7902.13, 133 | 134 | 8372.01, //C9 120 135 | 8869.84, //C#0.Db0 136 | 9397.27, 137 | 9956.06, 138 | 10548.0, 139 | 11175.3, 140 | 11839.8, 141 | 12543.8 142 | }; 143 | 144 | 145 | 146 | 147 | 148 | -------------------------------------------------------------------------------- /V2/Digital_Handpan_V2/TeensyAudioDesignTool.h: -------------------------------------------------------------------------------- 1 | //Import this code back into the Teensy Audio System Design Tool to alter any portion of this system 2 | 3 | // GUItool: begin automatically generated code 4 | AudioSynthWaveformDc dc2; //xy=189,206 5 | AudioSynthWaveformSine sine3; //xy=189,250 6 | AudioSynthWaveformDc dc6; //xy=188,564 7 | AudioSynthWaveformSine sine7; //xy=188,608 8 | AudioSynthWaveformSine sine2; //xy=190,164 9 | AudioSynthWaveformSine sine6; //xy=189,522 10 | AudioSynthWaveformSine sine1; //xy=192,78 11 | AudioSynthWaveformSine sine4; //xy=191,334 12 | AudioSynthWaveformDc dc1; //xy=192,120 13 | AudioSynthWaveformSine sine5; //xy=191,436 14 | AudioSynthWaveformSine sine8; //xy=190,692 15 | AudioSynthWaveformDc dc5; //xy=191,478 16 | AudioSynthWaveformDc dc4; //xy=192,378 17 | AudioSynthWaveformDc dc8; //xy=191,736 18 | AudioSynthWaveformDc dc3; //xy=194,294 19 | AudioSynthWaveformDc dc7; //xy=193,652 20 | AudioEffectMultiply multiply3; //xy=346,268 21 | AudioEffectMultiply multiply4; //xy=346,354 22 | AudioEffectMultiply multiply7; //xy=345,626 23 | AudioEffectMultiply multiply8; //xy=345,712 24 | AudioEffectMultiply multiply2; //xy=350,184 25 | AudioEffectMultiply multiply6; //xy=349,542 26 | AudioEffectMultiply multiply1; //xy=353,95 27 | AudioEffectMultiply multiply5; //xy=352,453 28 | AudioMixer4 mixer1; //xy=565,245 29 | AudioMixer4 mixer2; //xy=564,603 30 | AudioMixer4 mixerMain; //xy=736,418 31 | AudioOutputI2S i2s1; //xy=881,466 32 | AudioConnection patchCord1(dc2, 0, multiply2, 1); 33 | AudioConnection patchCord2(sine3, 0, multiply3, 0); 34 | AudioConnection patchCord3(dc6, 0, multiply6, 1); 35 | AudioConnection patchCord4(sine7, 0, multiply7, 0); 36 | AudioConnection patchCord5(sine2, 0, multiply2, 0); 37 | AudioConnection patchCord6(sine6, 0, multiply6, 0); 38 | AudioConnection patchCord7(sine1, 0, multiply1, 0); 39 | AudioConnection patchCord8(sine4, 0, multiply4, 0); 40 | AudioConnection patchCord9(dc1, 0, multiply1, 1); 41 | AudioConnection patchCord10(sine5, 0, multiply5, 0); 42 | AudioConnection patchCord11(sine8, 0, multiply8, 0); 43 | AudioConnection patchCord12(dc5, 0, multiply5, 1); 44 | AudioConnection patchCord13(dc4, 0, multiply4, 1); 45 | AudioConnection patchCord14(dc8, 0, multiply8, 1); 46 | AudioConnection patchCord15(dc3, 0, multiply3, 1); 47 | AudioConnection patchCord16(dc7, 0, multiply7, 1); 48 | AudioConnection patchCord17(multiply3, 0, mixer1, 2); 49 | AudioConnection patchCord18(multiply4, 0, mixer1, 3); 50 | AudioConnection patchCord19(multiply7, 0, mixer2, 2); 51 | AudioConnection patchCord20(multiply8, 0, mixer2, 3); 52 | AudioConnection patchCord21(multiply2, 0, mixer1, 1); 53 | AudioConnection patchCord22(multiply6, 0, mixer2, 1); 54 | AudioConnection patchCord23(multiply1, 0, mixer1, 0); 55 | AudioConnection patchCord24(multiply5, 0, mixer2, 0); 56 | AudioConnection patchCord25(mixer1, 0, mixerMain, 0); 57 | AudioConnection patchCord26(mixer2, 0, mixerMain, 1); 58 | AudioConnection patchCord27(mixerMain, 0, i2s1, 0); 59 | AudioConnection patchCord28(mixerMain, 0, i2s1, 1); 60 | AudioControlSGTL5000 sgtl5000_1; //xy=528,409 61 | // GUItool: end automatically generated code 62 | -------------------------------------------------------------------------------- /V1/Digital_Handpan_Poly_Touch_Sense/TeensyAudioDesignTool.h: -------------------------------------------------------------------------------- 1 | //Import this code back into the Teensy Audio System Design Tool to alter any portion of this system 2 | 3 | // GUItool: begin automatically generated code 4 | AudioSynthWaveformDc dc2; //xy=189,206 5 | AudioSynthWaveformSine sine3; //xy=189,250 6 | AudioSynthWaveformDc dc6; //xy=188,564 7 | AudioSynthWaveformSine sine7; //xy=188,608 8 | AudioSynthWaveformSine sine2; //xy=190,164 9 | AudioSynthWaveformSine sine6; //xy=189,522 10 | AudioSynthWaveformSine sine1; //xy=192,78 11 | AudioSynthWaveformSine sine4; //xy=191,334 12 | AudioSynthWaveformDc dc1; //xy=192,120 13 | AudioSynthWaveformSine sine5; //xy=191,436 14 | AudioSynthWaveformSine sine8; //xy=190,692 15 | AudioSynthWaveformDc dc5; //xy=191,478 16 | AudioSynthWaveformDc dc4; //xy=192,378 17 | AudioSynthWaveformDc dc8; //xy=191,736 18 | AudioSynthWaveformDc dc3; //xy=194,294 19 | AudioSynthWaveformDc dc7; //xy=193,652 20 | AudioEffectMultiply multiply3; //xy=346,268 21 | AudioEffectMultiply multiply4; //xy=346,354 22 | AudioEffectMultiply multiply7; //xy=345,626 23 | AudioEffectMultiply multiply8; //xy=345,712 24 | AudioEffectMultiply multiply2; //xy=350,184 25 | AudioEffectMultiply multiply6; //xy=349,542 26 | AudioEffectMultiply multiply1; //xy=353,95 27 | AudioEffectMultiply multiply5; //xy=352,453 28 | AudioMixer4 mixer1; //xy=565,245 29 | AudioMixer4 mixer2; //xy=564,603 30 | AudioMixer4 mixerMain; //xy=736,418 31 | AudioOutputI2S i2s1; //xy=881,466 32 | AudioConnection patchCord1(dc2, 0, multiply2, 1); 33 | AudioConnection patchCord2(sine3, 0, multiply3, 0); 34 | AudioConnection patchCord3(dc6, 0, multiply6, 1); 35 | AudioConnection patchCord4(sine7, 0, multiply7, 0); 36 | AudioConnection patchCord5(sine2, 0, multiply2, 0); 37 | AudioConnection patchCord6(sine6, 0, multiply6, 0); 38 | AudioConnection patchCord7(sine1, 0, multiply1, 0); 39 | AudioConnection patchCord8(sine4, 0, multiply4, 0); 40 | AudioConnection patchCord9(dc1, 0, multiply1, 1); 41 | AudioConnection patchCord10(sine5, 0, multiply5, 0); 42 | AudioConnection patchCord11(sine8, 0, multiply8, 0); 43 | AudioConnection patchCord12(dc5, 0, multiply5, 1); 44 | AudioConnection patchCord13(dc4, 0, multiply4, 1); 45 | AudioConnection patchCord14(dc8, 0, multiply8, 1); 46 | AudioConnection patchCord15(dc3, 0, multiply3, 1); 47 | AudioConnection patchCord16(dc7, 0, multiply7, 1); 48 | AudioConnection patchCord17(multiply3, 0, mixer1, 2); 49 | AudioConnection patchCord18(multiply4, 0, mixer1, 3); 50 | AudioConnection patchCord19(multiply7, 0, mixer2, 2); 51 | AudioConnection patchCord20(multiply8, 0, mixer2, 3); 52 | AudioConnection patchCord21(multiply2, 0, mixer1, 1); 53 | AudioConnection patchCord22(multiply6, 0, mixer2, 1); 54 | AudioConnection patchCord23(multiply1, 0, mixer1, 0); 55 | AudioConnection patchCord24(multiply5, 0, mixer2, 0); 56 | AudioConnection patchCord25(mixer1, 0, mixerMain, 0); 57 | AudioConnection patchCord26(mixer2, 0, mixerMain, 1); 58 | AudioConnection patchCord27(mixerMain, 0, i2s1, 0); 59 | AudioConnection patchCord28(mixerMain, 0, i2s1, 1); 60 | AudioControlSGTL5000 sgtl5000_1; //xy=528,409 61 | // GUItool: end automatically generated code 62 | -------------------------------------------------------------------------------- /V1/Digital_Handpan_Poly_Touch_Sense/Digital_Handpan_Poly_Touch_Sense.ino: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | Digital Handpan Code for Teesny 3 | Joel Bartlett @ SparkFun Electronics 4 | Original Creation Date: October 16, 2016 5 | 6 | This sketch produces polyphonic notes when any number of eight capacitive touch pads are 7 | touched, thus replicating a Handpan (or Hang) steel drum. This sketch 8 | makes use of the Teensy Audio Shield (https://www.sparkfun.com/products/12767) 9 | as well as the Teensy Audio System Design Tool (http://www.pjrc.com/teensy/gui/). 10 | All capactive touch sensing is handled by the Teensy's built in Touch Sense Pins. 11 | 12 | Hardware: 13 | Teensy 3.2 Dev Board (https://www.sparkfun.com/products/13736) 14 | Teensy Audio Board (https://www.sparkfun.com/products/12767) 15 | Various buttons and potentiometers 16 | 17 | Development environment specifics: 18 | IDE: Arduino IDE V 1.6.11 with the Teensyduino Add-on installed V Teensy Loader V1.30 19 | 20 | This code is beerware; if you see me (or any other SparkFun 21 | employee) at the local, and you've found our code helpful, 22 | please buy us a round! 23 | Distributed as-is; no warranty is given. 24 | *******************************************************************************/ 25 | //These libraries are included by the Teensy Audio System Design Tool 26 | #include 27 | #include 28 | #include 29 | //#include //not using the SD library at this time 30 | #include 31 | #include 32 | 33 | #include "note_frequency.h" 34 | #include "scales.h" 35 | #include "TeensyAudioDesignTool.h" 36 | 37 | //an array to define each of the eight touch sense pins, 38 | //all other touch sense pins are used by the Teensy Audio Shield (16,17,18,19) 39 | int pinTouch[] = {33,32,25,17,16,15,1,0}; 40 | 41 | int scale_index = 0;//var to keep track fo which scale is being used 42 | 43 | int dcVal = 0;//value to control the decay of each note 44 | 45 | //buttons for incrementing or decrementing through each scale 46 | Bounce button0 = Bounce(2, 15); 47 | Bounce button1 = Bounce(3, 15); 48 | 49 | bool debug = 0;//Set to 1 for Serial debugging 50 | 51 | //////////////////////////////////////////////////////// 52 | void setup() 53 | { 54 | //initialize buttons 55 | pinMode(2, INPUT_PULLUP); 56 | pinMode(3, INPUT_PULLUP); 57 | button0.update(); 58 | button1.update(); 59 | 60 | //initialize Serial 61 | Serial.begin(115200); 62 | 63 | //set aside audio memory 64 | AudioMemory(64); 65 | 66 | //initialize audio settings 67 | sine1.amplitude(0.125); 68 | sine1.frequency(440); 69 | sine2.amplitude(0.125); 70 | sine2.frequency(440); 71 | sine3.amplitude(0.125); 72 | sine3.frequency(440); 73 | sine4.amplitude(0.125); 74 | sine4.frequency(440); 75 | sine5.amplitude(0.125); 76 | sine5.frequency(440); 77 | sine6.amplitude(0.125); 78 | sine6.frequency(440); 79 | sine7.amplitude(0.125); 80 | sine7.frequency(440); 81 | sine8.amplitude(0.125); 82 | sine8.frequency(440); 83 | 84 | dc1.amplitude(0); 85 | dc2.amplitude(0); 86 | dc3.amplitude(0); 87 | dc4.amplitude(0); 88 | dc5.amplitude(0); 89 | dc6.amplitude(0); 90 | dc7.amplitude(0); 91 | dc8.amplitude(0); 92 | 93 | //initialize volume 94 | sgtl5000_1.enable(); 95 | sgtl5000_1.volume(0.8); 96 | //enable line out for troubleshooting on O-scope 97 | //sgtl5000_1.unmuteLineout(); 98 | 99 | } 100 | ////////////////////////////////////////////// 101 | void loop() 102 | { 103 | volumeCheck();//check the volume knob 104 | 105 | touchCheck();//check if any of the capacitive pads have been touched 106 | 107 | dcValCheck();//check the decay knob 108 | 109 | buttonCheck();//check for button presses to change the scale 110 | 111 | } 112 | ///////////////////////////////////////////////////// 113 | void volumeCheck() 114 | { 115 | //check knob value for volume 116 | int knob = analogRead(A7); 117 | float vol = (float)knob / 1280.0; 118 | sgtl5000_1.volume(vol); 119 | 120 | if(debug == 1) 121 | { 122 | Serial.print("A7 = "); 123 | Serial.println(knob); 124 | } 125 | } 126 | ///////////////////////////////////////////////////// 127 | void dcValCheck() 128 | { 129 | //check knob and set value as delay on dc constant for sine wave decay 130 | dcVal = map(analogRead(A6), 0, 1023, 1, 1000); 131 | 132 | if(debug == 1) 133 | { 134 | Serial.print("A6 = "); 135 | Serial.println(dcVal); 136 | } 137 | 138 | } 139 | ///////////////////////////////////////////////////// 140 | void touchCheck() 141 | { 142 | //Each capacitive touch pad will vary based on the size and material it is made of 143 | //The value necessary to trigger each note will require some trial and error to get the 144 | //sensitivity just right. Try adjusting these values to get the best response. 145 | 146 | if (touchRead(pinTouch[0]) > 2000) 147 | { 148 | //once a pad is touched, a value from the note frquency froma table is looked up via a 2D table 149 | //with x corresponding to a scale and y corresponding to one of the eight notes on the drum. 150 | 151 | sine1.frequency(note_frequency[scale[scale_index][0]]); 152 | dc1.amplitude(1.0, 5); 153 | } 154 | if (touchRead(pinTouch[0]) <= 2000) 155 | { 156 | //one the pad is released, the note fades out with a decay val set by the dcVal knob 157 | dc1.amplitude(0, dcVal); 158 | } 159 | 160 | 161 | if (touchRead(pinTouch[1]) > 2000) 162 | { 163 | sine2.frequency(note_frequency[scale[scale_index][1]]); 164 | dc2.amplitude(1.0, 5); 165 | } 166 | if (touchRead(pinTouch[1]) <= 2000) 167 | { 168 | dc2.amplitude(0, dcVal); 169 | } 170 | 171 | 172 | if (touchRead(pinTouch[2]) > 2000) 173 | { 174 | sine3.frequency(note_frequency[scale[scale_index][2]]); 175 | dc3.amplitude(1.0, 5); 176 | } 177 | if (touchRead(pinTouch[2]) <= 2000) 178 | { 179 | dc3.amplitude(0, dcVal); 180 | } 181 | 182 | 183 | if (touchRead(pinTouch[3]) > 2000) 184 | { 185 | sine4.frequency(note_frequency[scale[scale_index][3]]); 186 | dc4.amplitude(1.0, 5); 187 | } 188 | if (touchRead(pinTouch[3]) <= 2000) 189 | { 190 | dc4.amplitude(0, dcVal); 191 | } 192 | 193 | if (touchRead(pinTouch[4]) > 2000) 194 | { 195 | sine5.frequency(note_frequency[scale[scale_index][4]]); 196 | dc5.amplitude(1.0, 5); 197 | } 198 | if (touchRead(pinTouch[4]) <= 2000) 199 | { 200 | dc5.amplitude(0, dcVal); 201 | } 202 | 203 | if (touchRead(pinTouch[5]) > 2000) 204 | { 205 | sine6.frequency(note_frequency[scale[scale_index][5]]); 206 | dc6.amplitude(1.0, 5); 207 | } 208 | if (touchRead(pinTouch[5]) <= 2000) 209 | { 210 | dc6.amplitude(0, dcVal); 211 | } 212 | 213 | 214 | 215 | if (touchRead(pinTouch[6]) > 2000) 216 | { 217 | sine7.frequency(note_frequency[scale[scale_index][6]]); 218 | dc7.amplitude(1.0, 5); 219 | } 220 | if (touchRead(pinTouch[6]) <= 2000) 221 | { 222 | dc7.amplitude(0, dcVal); 223 | } 224 | 225 | 226 | if (touchRead(pinTouch[7]) > 2000) 227 | { 228 | sine8.frequency(note_frequency[scale[scale_index][7]]); 229 | dc8.amplitude(1.0, 5); 230 | } 231 | if (touchRead(pinTouch[7]) <= 2000) 232 | { 233 | dc8.amplitude(0, dcVal); 234 | } 235 | 236 | 237 | 238 | } 239 | ////////////////////////////////////////////////// 240 | void buttonCheck() 241 | { 242 | button0.update(); 243 | button1.update(); 244 | 245 | //if button 0 is pressed, increment the scale being used 246 | if (button0.risingEdge()) 247 | { 248 | scale_index++; 249 | //check for overflow 250 | if(scale_index > numOfScales)//numOfScales variable found in the scales.h file 251 | scale_index = 0; 252 | } 253 | 254 | //if button 1 is pressed, decrement the scale being used 255 | if (button1.risingEdge()) 256 | { 257 | scale_index--; 258 | //check for negative numbers 259 | if(scale_index < 0) 260 | scale_index = numOfScales;//numOfScales variable found in the scales.h file 261 | } 262 | 263 | if(debug == 1) 264 | { 265 | Serial.print("Scale = "); 266 | Serial.println(scale_index); 267 | } 268 | } 269 | -------------------------------------------------------------------------------- /V2/Digital_Handpan_V2/Digital_Handpan_V2.ino: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | Digital Handpan V2 Code for Teesny 3 | Joel Bartlett @ SparkFun Electronics 4 | Original Creation Date: December 16, 2017 5 | 6 | This sketch produces polyphonic notes when any number of eight capacitive touch pads are 7 | touched, thus replicating a Handpan (or Hang) steel drum. This sketch 8 | makes use of the Teensy Audio Shield (https://www.sparkfun.com/products/12767) 9 | as well as the Teensy Audio System Design Tool (http://www.pjrc.com/teensy/gui/). 10 | All capactive touch sensing is handled by the Teensy's built in Touch Sense Pins. 11 | 12 | Hardware: 13 | Teensy 3.2 Dev Board (https://www.sparkfun.com/products/13736) 14 | Teensy Audio Board (https://www.sparkfun.com/products/12767) 15 | Teensy View OLED Screen (https://www.sparkfun.com/products/14048) 16 | Various buttons and potentiometers 17 | 18 | Development environment specifics: 19 | IDE: Arduino IDE V 1.8.5 with the Teensyduino Add-on installed V Teensy Loader V1.30 20 | 21 | This code is beerware; if you see me (or any other SparkFun 22 | employee) at the local, and you've found our code helpful, 23 | please buy us a round! 24 | Distributed as-is; no warranty is given. 25 | *******************************************************************************/ 26 | //These libraries are included by the Teensy Audio System Design Tool 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | #define MAX17043_ADDRESS 0x36// Battery Fuel Gauge 37 | 38 | #include "note_frequency.h" 39 | #include "TeensyAudioDesignTool.h" 40 | 41 | //Alternate (Audio) Teensy View Setup 42 | #define PIN_RESET 2 43 | #define PIN_DC 21 44 | #define PIN_CS 20 45 | #define PIN_SCK 14 46 | #define PIN_MOSI 7 47 | 48 | 49 | #define volKnob A13 //grey wire 50 | #define decayKnob A12 //black wire 51 | 52 | MAX17043GU battery; 53 | TeensyView oled(PIN_RESET, PIN_DC, PIN_CS, PIN_SCK, PIN_MOSI); 54 | 55 | //an array to define each of the eight touch sense pins, 56 | //all other touch sense pins are used by the Teensy Audio Shield (16,17,18,19) 57 | int pinTouch[] = {0,1,15,16,17,25,32,33}; //25 = white, 32 = yellow, 33 = blue 58 | 59 | int scale_index = 0;//var to keep track fo which scale is being used 60 | int note_index = 57;//starting note value (A) 61 | int octave_index = 0; 62 | 63 | int dcVal = 0;//value to control the decay of each note 64 | int padNumber = 0;//debug for printing pad values to OLED 65 | 66 | ////////////////////CHANGE THIS WHEN ADDING MORE SCALES 67 | int numOfScales = 10 ;//indexed at zero (subtract 1) 68 | /////////////////////////////////////////////////////// 69 | 70 | int scale[8]; 71 | 72 | //buttons for incrementing or decrementing through each scale 73 | Bounce button0 = Bounce(4, 15); 74 | Bounce button1 = Bounce(3, 15); 75 | //buttons for incrementing or decrementing the octave 76 | Bounce foot0 = Bounce(5, 30); 77 | Bounce foot1 = Bounce(8, 30); 78 | 79 | float vol = 0; 80 | 81 | float voltage; 82 | float percentage; 83 | 84 | int counter = 0; 85 | 86 | bool debug = false; 87 | //////////////////////////////////////////////////////// 88 | void setup() 89 | { 90 | //initialize buttons 91 | pinMode(4, INPUT_PULLUP); 92 | pinMode(3, INPUT_PULLUP); 93 | pinMode(5, INPUT_PULLUP); 94 | pinMode(8, INPUT_PULLUP); 95 | button0.update(); 96 | button1.update(); 97 | foot0.update(); 98 | foot1.update(); 99 | 100 | //initialize Serial 101 | Serial.begin(115200); 102 | 103 | // Start I2C 104 | Wire.begin(); 105 | delay(100); 106 | battery.restart(); 107 | 108 | //set aside audio memory 109 | AudioMemory(64); 110 | 111 | //initialize audio settings 112 | sine1.amplitude(0.125); 113 | sine1.frequency(440); 114 | sine2.amplitude(0.125); 115 | sine2.frequency(440); 116 | sine3.amplitude(0.125); 117 | sine3.frequency(440); 118 | sine4.amplitude(0.125); 119 | sine4.frequency(440); 120 | sine5.amplitude(0.125); 121 | sine5.frequency(440); 122 | sine6.amplitude(0.125); 123 | sine6.frequency(440); 124 | sine7.amplitude(0.125); 125 | sine7.frequency(440); 126 | sine8.amplitude(0.125); 127 | sine8.frequency(440); 128 | 129 | dc1.amplitude(0); 130 | dc2.amplitude(0); 131 | dc3.amplitude(0); 132 | dc4.amplitude(0); 133 | dc5.amplitude(0); 134 | dc6.amplitude(0); 135 | dc7.amplitude(0); 136 | dc8.amplitude(0); 137 | 138 | 139 | //initialize volume 140 | sgtl5000_1.enable(); 141 | sgtl5000_1.volume(0.8); 142 | sgtl5000_1.lineOutLevel(5); 143 | 144 | //Initialize the OLED 145 | oled.begin(); 146 | // clear(ALL) will clear out the OLED's graphic memory. 147 | // clear(PAGE) will clear the Arduino's display buffer. 148 | oled.clear(ALL); // Clear the display's memory (gets rid of artifacts) 149 | // To actually draw anything on the display, you must call the 150 | // display() function. 151 | oled.display(); 152 | // Give the splash screen some time to shine 153 | delay(1000); 154 | 155 | changeScale();//start off at middle C 156 | } 157 | ////////////////////////////////////////////// 158 | void loop() 159 | { 160 | volumeCheck();//check the volume knob 161 | 162 | touchCheck();//check if any of the capacitive pads have been touched 163 | 164 | dcValCheck();//check the decay knob 165 | 166 | buttonCheck();//check for button presses to change the scale 167 | 168 | counter++; 169 | if(counter == 10000);//don't check battery all the time, slows opperation 170 | { 171 | getBattery(); 172 | counter = 0; 173 | } 174 | 175 | oledPrint();//print to TeensyView 176 | 177 | } 178 | void getBattery() 179 | { 180 | // Get the values 181 | voltage = battery.voltageLevel(); 182 | percentage = battery.fuelLevel(); 183 | } 184 | void oledPrint() 185 | { 186 | oled.clear(PAGE); 187 | 188 | oled.setCursor(0, 0); 189 | oled.print("Scale = "); 190 | 191 | if(note_index == 60) 192 | oled.print("C "); 193 | if(note_index == 61) 194 | oled.print("C# "); 195 | if(note_index == 62) 196 | oled.print("D "); 197 | if(note_index == 63) 198 | oled.print("D# "); 199 | if(note_index == 64) 200 | oled.print("E "); 201 | if(note_index == 65) 202 | oled.print("F "); 203 | if(note_index == 66) 204 | oled.print("F# "); 205 | if(note_index == 67) 206 | oled.print("G "); 207 | if(note_index == 68) 208 | oled.print("G# "); 209 | if(note_index == 57) 210 | oled.print("A "); 211 | if(note_index == 58) 212 | oled.print("A# "); 213 | if(note_index == 59) 214 | oled.print("B "); 215 | 216 | 217 | if(scale_index == 0) 218 | oled.print("Major"); 219 | if(scale_index == 1) 220 | oled.print("Minor"); 221 | if(scale_index == 2) 222 | oled.print("Akebono"); 223 | if(scale_index == 3) 224 | oled.print("Pygmy"); 225 | if(scale_index == 4) 226 | oled.print("Equinox"); 227 | if(scale_index == 5) 228 | oled.print("Sapphire"); 229 | if(scale_index == 6) 230 | oled.print("Gypsy"); 231 | if(scale_index == 7) 232 | oled.print("SlvrSpring"); 233 | if(scale_index == 8) 234 | oled.print("Integral"); 235 | if(scale_index == 9) 236 | oled.print("Dorian"); 237 | if(scale_index == 10) 238 | oled.print("GldArcadia"); 239 | 240 | oled.setCursor(0, 8); 241 | oled.print("Volume = "); 242 | int newVol = map(vol, 0.0, 0.8, 0, 100); 243 | oled.print(newVol); 244 | oled.print("%"); 245 | 246 | oled.setCursor(0, 16); 247 | oled.print("Decay = "); 248 | oled.print((int)dcVal/10); 249 | oled.print("% Oct:"); 250 | oled.print(octave_index); 251 | 252 | 253 | oled.setCursor(0, 24); 254 | oled.print("Batt = "); 255 | oled.print(percentage); 256 | oled.print("% "); 257 | oled.print(voltage); 258 | oled.print("V"); 259 | 260 | oled.display(); 261 | 262 | delay(10); 263 | } 264 | ///////////////////////////////////////////////////// 265 | void volumeCheck() 266 | { 267 | vol = (float)analogRead(volKnob) / 1280.0; 268 | 269 | mixerMain.gain(0, vol); 270 | mixerMain.gain(1, vol); 271 | } 272 | ///////////////////////////////////////////////////// 273 | void dcValCheck() 274 | { 275 | //check knob and set value as delay on dc constant for sine wave decay 276 | dcVal = map(analogRead(decayKnob), 0, 1023, 1, 1000); 277 | } 278 | ///////////////////////////////////////////////////// 279 | void touchCheck() 280 | { 281 | //Each capacitive touch pad will vary based on the size and material it is made of 282 | //The value necessary to trigger each note will require some trial and error to get the 283 | //sensitivity just right. Try adjusting these values to get the best response. 284 | 285 | if (touchRead(pinTouch[0]) > 1800) 286 | { 287 | //once a pad is touched, a value from the note frquency froma table is looked up via a 2D table 288 | //with x corresponding to a scale and y corresponding to one of the eight notes on the drum. 289 | 290 | if(octave_index == 1) 291 | sine1.frequency(note_frequency[scale[0]+12]); 292 | else if(octave_index == -1) 293 | sine1.frequency(note_frequency[scale[0]-12]); 294 | else if(octave_index == 2) 295 | sine1.frequency(note_frequency[scale[0]+24]); 296 | else if(octave_index == -2) 297 | sine1.frequency(note_frequency[scale[0]-24]); 298 | else 299 | sine1.frequency(note_frequency[scale[0]]); 300 | dc1.amplitude(1.0, 5); 301 | } 302 | if (touchRead(pinTouch[0]) <= 1800) 303 | { 304 | //one the pad is released, the note fades out with a decay val set by the dcVal knob 305 | dc1.amplitude(0, dcVal); 306 | } 307 | 308 | 309 | if (touchRead(pinTouch[1]) > 1800) 310 | { 311 | if(octave_index == 1) 312 | sine2.frequency(note_frequency[scale[1]+12]); 313 | else if(octave_index == -1) 314 | sine2.frequency(note_frequency[scale[1]-12]); 315 | else if(octave_index == 2) 316 | sine2.frequency(note_frequency[scale[1]+24]); 317 | else if(octave_index == -2) 318 | sine2.frequency(note_frequency[scale[1]-24]); 319 | else 320 | sine2.frequency(note_frequency[scale[1]]); 321 | dc2.amplitude(1.0, 5); 322 | } 323 | if (touchRead(pinTouch[1]) <= 1800) 324 | { 325 | dc2.amplitude(0, dcVal); 326 | } 327 | 328 | 329 | if (touchRead(pinTouch[2]) > 1900) 330 | { 331 | if(octave_index == 1) 332 | sine3.frequency(note_frequency[scale[2]+12]); 333 | else if(octave_index == -1) 334 | sine3.frequency(note_frequency[scale[2]-12]); 335 | else if(octave_index == 2) 336 | sine3.frequency(note_frequency[scale[2]+24]); 337 | else if(octave_index == -2) 338 | sine3.frequency(note_frequency[scale[2]-24]); 339 | else 340 | sine3.frequency(note_frequency[scale[2]]); 341 | dc3.amplitude(1.0, 5); 342 | } 343 | if (touchRead(pinTouch[2]) <= 1900) 344 | { 345 | dc3.amplitude(0, dcVal); 346 | } 347 | 348 | 349 | if (touchRead(pinTouch[3]) > 1800) 350 | { 351 | if(octave_index == 1) 352 | sine4.frequency(note_frequency[scale[3]+12]); 353 | else if(octave_index == -1) 354 | sine4.frequency(note_frequency[scale[3]-12]); 355 | else if(octave_index == 2) 356 | sine4.frequency(note_frequency[scale[3]+24]); 357 | else if(octave_index == -2) 358 | sine4.frequency(note_frequency[scale[3]-24]); 359 | else 360 | sine4.frequency(note_frequency[scale[3]]); 361 | dc4.amplitude(1.0, 5); 362 | } 363 | if (touchRead(pinTouch[3]) <= 1800) 364 | { 365 | dc4.amplitude(0, dcVal); 366 | } 367 | 368 | if (touchRead(pinTouch[4]) > 1800) 369 | { 370 | if(octave_index == 1) 371 | sine5.frequency(note_frequency[scale[4]+12]); 372 | else if(octave_index == -1) 373 | sine5.frequency(note_frequency[scale[4]-12]); 374 | else if(octave_index == 2) 375 | sine5.frequency(note_frequency[scale[4]+24]); 376 | else if(octave_index == -2) 377 | sine5.frequency(note_frequency[scale[4]-24]); 378 | else 379 | sine5.frequency(note_frequency[scale[4]]); 380 | dc5.amplitude(1.0, 5); 381 | } 382 | if (touchRead(pinTouch[4]) <= 1800) 383 | { 384 | dc5.amplitude(0, dcVal); 385 | } 386 | 387 | if (touchRead(pinTouch[5]) > 1800) 388 | { 389 | if(octave_index == 1) 390 | sine6.frequency(note_frequency[scale[5]+12]); 391 | else if(octave_index == -1) 392 | sine6.frequency(note_frequency[scale[5]-12]); 393 | else if(octave_index == 2) 394 | sine6.frequency(note_frequency[scale[5]+24]); 395 | else if(octave_index == -2) 396 | sine6.frequency(note_frequency[scale[5]-24]); 397 | else 398 | sine6.frequency(note_frequency[scale[5]]); 399 | dc6.amplitude(1.0, 5); 400 | } 401 | if (touchRead(pinTouch[5]) <= 1800) 402 | { 403 | dc6.amplitude(0, dcVal); 404 | } 405 | 406 | 407 | 408 | if (touchRead(pinTouch[6]) > 1800) 409 | { 410 | if(octave_index == 1) 411 | sine7.frequency(note_frequency[scale[6]+12]); 412 | else if(octave_index == -1) 413 | sine7.frequency(note_frequency[scale[6]-12]); 414 | else if(octave_index == 2) 415 | sine7.frequency(note_frequency[scale[6]+24]); 416 | else if(octave_index == -2) 417 | sine7.frequency(note_frequency[scale[6]-24]); 418 | else 419 | sine7.frequency(note_frequency[scale[6]]); 420 | dc7.amplitude(1.0, 5); 421 | } 422 | if (touchRead(pinTouch[6]) <= 1800) 423 | { 424 | dc7.amplitude(0, dcVal); 425 | } 426 | 427 | 428 | if (touchRead(pinTouch[7]) > 1700) 429 | { 430 | if(octave_index == 1) 431 | sine8.frequency(note_frequency[scale[7]+12]); 432 | else if(octave_index == -1) 433 | sine8.frequency(note_frequency[scale[7]-12]); 434 | else if(octave_index == 2) 435 | sine8.frequency(note_frequency[scale[7]+24]); 436 | else if(octave_index == -2) 437 | sine8.frequency(note_frequency[scale[7]-24]); 438 | else 439 | sine8.frequency(note_frequency[scale[7]]); 440 | dc8.amplitude(1.0, 5); 441 | } 442 | if (touchRead(pinTouch[7]) <= 1700) 443 | { 444 | dc8.amplitude(0, dcVal); 445 | } 446 | 447 | 448 | 449 | } 450 | ////////////////////////////////////////////////// 451 | void buttonCheck() 452 | { 453 | button0.update(); 454 | button1.update(); 455 | foot0.update(); 456 | foot1.update(); 457 | 458 | //if button 0 is pressed, increment the scale being used 459 | if (button0.fallingEdge()) 460 | { 461 | 462 | note_index++; 463 | padNumber++; 464 | //check for overflow 465 | if(note_index > 68) 466 | { 467 | note_index = 57; 468 | } 469 | if(padNumber > 7) 470 | { 471 | padNumber = 0; 472 | } 473 | octave_index = 0; 474 | changeScale(); 475 | } 476 | 477 | //if button 1 is pressed, decrement the scale being used 478 | if (button1.fallingEdge()) 479 | { 480 | scale_index++; 481 | padNumber--; 482 | //check for overflow 483 | if(scale_index > numOfScales) 484 | { 485 | scale_index = 0; 486 | } 487 | if(padNumber < 0) 488 | { 489 | padNumber = 7; 490 | } 491 | 492 | octave_index = 0; 493 | changeScale(); 494 | } 495 | 496 | //if foot pedal 0 is pressed, increment the octave 497 | if (foot0.risingEdge()) 498 | { 499 | octave_index++; 500 | 501 | if(octave_index > 2) 502 | octave_index = 2; 503 | } 504 | 505 | //if button 1 is pressed, decrement the scale being used 506 | if (foot1.risingEdge()) 507 | { 508 | octave_index--; 509 | 510 | if(octave_index < -2) 511 | octave_index = -2; 512 | } 513 | 514 | 515 | } 516 | void changeScale() 517 | { 518 | //Change numOfScales variable at top if adding new scale!! 519 | 520 | int root = note_index; 521 | 522 | if(scale_index == 0)//Major Scale 2,2,3,2,3,2,2 (WholeStep, WS, WS+HalfStep, WS, WS+HS, WS, WS) 523 | { 524 | scale[0] = root; 525 | scale[1] = root+2; 526 | scale[2] = root+4; 527 | scale[3] = root+7; 528 | scale[4] = root+9; 529 | scale[5] = root+12; 530 | scale[6] = root+14; 531 | scale[7] = root+16; 532 | } 533 | if(scale_index == 1)//Minor Scale 3,2,2,3,2,3,2 534 | { 535 | scale[0] = root; 536 | scale[1] = root+3; 537 | scale[2] = root+5; 538 | scale[3] = root+7; 539 | scale[4] = root+10; 540 | scale[5] = root+12; 541 | scale[6] = root+15; 542 | scale[7] = root+17; 543 | } 544 | if(scale_index == 2)//Akebono Scale 2,1,4,1,4,2,1 545 | { 546 | scale[0] = root; 547 | scale[1] = root+2; 548 | scale[2] = root+3; 549 | scale[3] = root+7; 550 | scale[4] = root+8; 551 | scale[5] = root+12; 552 | scale[6] = root+14; 553 | scale[7] = root+15; 554 | } 555 | if(scale_index == 3)//Pygmy Scale 2,1,4,3,2,2,1 556 | { 557 | scale[0] = root; 558 | scale[1] = root+2; 559 | scale[2] = root+3; 560 | scale[3] = root+7; 561 | scale[4] = root+10; 562 | scale[5] = root+12; 563 | scale[6] = root+14; 564 | scale[7] = root+15; 565 | } 566 | if(scale_index == 4)//Equinox Scale 4,1,2,2,2,1,4 567 | { 568 | scale[0] = root; 569 | scale[1] = root+4; 570 | scale[2] = root+5; 571 | scale[3] = root+7; 572 | scale[4] = root+9; 573 | scale[5] = root+11; 574 | scale[6] = root+12; 575 | scale[7] = root+16; 576 | } 577 | if(scale_index == 5)//Sapphire 3,2,4,1,2,3,2 578 | { 579 | scale[0] = root; 580 | scale[1] = root+3; 581 | scale[2] = root+5; 582 | scale[3] = root+9; 583 | scale[4] = root+10; 584 | scale[5] = root+12; 585 | scale[6] = root+15; 586 | scale[7] = root+17; 587 | } 588 | if(scale_index == 6)//Gypsy 1,3,1,2,1,2,2 589 | { 590 | scale[0] = root; 591 | scale[1] = root+1; 592 | scale[2] = root+4; 593 | scale[3] = root+5; 594 | scale[4] = root+7; 595 | scale[5] = root+8; 596 | scale[6] = root+10; 597 | scale[7] = root+12; 598 | } 599 | if(scale_index == 7)//Silver Spring 4,1,2,2,3,4,1 600 | { 601 | scale[0] = root; 602 | scale[1] = root+4; 603 | scale[2] = root+5; 604 | scale[3] = root+7; 605 | scale[4] = root+9; 606 | scale[5] = root+12; 607 | scale[6] = root+16; 608 | scale[7] = root+17; 609 | } 610 | if(scale_index == 8)//Integral 2,1,4,1,2,2,2 611 | { 612 | scale[0] = root; 613 | scale[1] = root+2; 614 | scale[2] = root+3; 615 | scale[3] = root+7; 616 | scale[4] = root+8; 617 | scale[5] = root+10; 618 | scale[6] = root+12; 619 | scale[7] = root+14; 620 | } 621 | if(scale_index == 9)//Dorian 2,1,2,2,2,3,2 622 | { 623 | scale[0] = root; 624 | scale[1] = root+2; 625 | scale[2] = root+3; 626 | scale[3] = root+5; 627 | scale[4] = root+7; 628 | scale[5] = root+9; 629 | scale[6] = root+12; 630 | scale[7] = root+14; 631 | } 632 | if(scale_index == 10)//Golden Arcadia 4,3,4,1,2,4,1 633 | { 634 | scale[0] = root; 635 | scale[1] = root+4; 636 | scale[2] = root+7; 637 | scale[3] = root+11; 638 | scale[4] = root+12; 639 | scale[5] = root+14; 640 | scale[6] = root+18; 641 | scale[7] = root+19; 642 | } 643 | } 644 | 645 | --------------------------------------------------------------------------------