├── Docs and references ├── EWIFingeringOneWatts.pdf ├── MPX5010.pdf ├── casio-dh-recorder-fingering.png ├── joysticks.png └── mpx5010gp.png ├── LICENSE.md ├── MiniVI-cap ├── MiniVI-cap.ino └── evi1000.pdf ├── MiniWI-cap-pmt-ArcoreProMicro └── MiniWI-cap-pmt-ArcoreProMicro.ino ├── MiniWI-cap-pmt ├── MiniWI-cap-pmt-fingering-casiomod.png ├── MiniWI-cap-pmt-schematic.png ├── MiniWI-cap-pmt.ino ├── MiniWI-fingering-casiomod.png └── pmtver.png ├── MiniWI-cap ├── MiniWI-cap-schematic.png ├── MiniWI-cap.ino ├── capverbottom.png ├── capverinside.png └── capvertop.png ├── MiniWI-lite └── MiniWI-lite.ino ├── MiniWI ├── MiniWI-schematic.png ├── MiniWI.ino └── miniwifirstproto.png ├── README.md ├── T.WI ├── T.WI-fingering.pdf ├── T.WI-settings.pdf ├── T.WI.ino ├── curves.png ├── twi-a4-template.pdf ├── twi-cut.dxf ├── twi-examples.pdf ├── twi-joystick.png ├── twi-schematic.png ├── twi-side1.stl ├── twi-side2.stl └── twi-userguide.pdf ├── TeensieWI-FSR └── TeensieWI-FSR.ino ├── TeensieWI-mod ├── TeensieWI-mod.ino ├── twmod-schematic.png └── twmod.png └── TeensieWI ├── TeensieWI-fingering.png ├── TeensieWI-schematic.png └── TeensieWI.ino /Docs and references/EWIFingeringOneWatts.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trasselfrisyr/MiniWI/539163e4f242e2ff6e4cc9de6d08df4fdd62859f/Docs and references/EWIFingeringOneWatts.pdf -------------------------------------------------------------------------------- /Docs and references/MPX5010.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trasselfrisyr/MiniWI/539163e4f242e2ff6e4cc9de6d08df4fdd62859f/Docs and references/MPX5010.pdf -------------------------------------------------------------------------------- /Docs and references/casio-dh-recorder-fingering.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trasselfrisyr/MiniWI/539163e4f242e2ff6e4cc9de6d08df4fdd62859f/Docs and references/casio-dh-recorder-fingering.png -------------------------------------------------------------------------------- /Docs and references/joysticks.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trasselfrisyr/MiniWI/539163e4f242e2ff6e4cc9de6d08df4fdd62859f/Docs and references/joysticks.png -------------------------------------------------------------------------------- /Docs and references/mpx5010gp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trasselfrisyr/MiniWI/539163e4f242e2ff6e4cc9de6d08df4fdd62859f/Docs and references/mpx5010gp.png -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | {one line to give the program's name and a brief idea of what it does.} 635 | Copyright (C) {year} {name of author} 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | {project} Copyright (C) {year} {fullname} 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /MiniVI-cap/MiniVI-cap.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /* 5 | NAME: MiniVI Cap Touch ver. 6 | WRITTEN BY: JOHAN BERGLUND 7 | CREDITS: State machine from the Gordophone blog by GORDON GOOD 8 | DATE: 2016-05-11 9 | FILE SAVED AS: MiniVI-cap.ino 10 | FOR: Arduino Pro Mini, ATmega328, version with breakouts for A6 and A7 11 | CLOCK: 16.00 MHz CRYSTAL 12 | PROGRAMME FUNCTION: Wind Controller with EVI style key setup, Freescale MPX5010GP breath sensor, PS2 style thumb joystick 13 | for pb/mod control, potentiometers for base octave +/- and portamento speed, capacitive touch keys, output to 5-pin DIN MIDI 14 | 15 | HARDWARE NOTES: 16 | * For the MIDI connection, attach a MIDI out Female 180 Degree 5-Pin DIN socket to Arduino. 17 | * Socket is seen from solder tags at rear. 18 | * DIN-5 pinout is: _______ 19 | * pin 2 - GND / \ 20 | * pin 4 - 220 ohm resistor to +5V | 1 3 | MIDI jack 21 | * pin 5 - Arduino Pin 1 (TX) via a 220 ohm resistor | 4 5 | 22 | * all other pins - unconnected \___2___/ 23 | * 24 | * A potentiometer controls base octave setting up or down one octave from start note. 25 | * It is connected to Arduino pin A6. 26 | * 27 | * Left hand thumb joystick controls octaves. 28 | * Up/down axis is connected to Arduino pin A7. 29 | * 30 | * +1 31 | * ^ 32 | * < o > 33 | * v 34 | * -1 35 | * 36 | * A potentiometer controls portamento speed setting. 37 | * It is connected to Arduino pin A2. 38 | * 39 | * Right hand thumb joystick controls pitch bend and modulation. 40 | * Pitch bend and modulation are connected to Arduino pins A0 and A1, 41 | * on DIP rows. 42 | * 43 | * PB up 44 | * ^ 45 | * Mod < o > Mod 46 | * v 47 | * PB dn 48 | * 49 | * The Freescale MPX5010GP pressure sensor output (V OUT) is connected to Arduino pin A3. 50 | * 51 | * Sensor pinout 52 | * 1: V OUT (pin with indent) 53 | * 2: GND 54 | * 3: VCC (to 5V) 55 | * 4: n/c 56 | * 5: n/c 57 | * 6: n/c 58 | * 59 | * 60 | * Adafruit MPR121 board connected to Arduino I2C ports (A4-SDA and A5-SCL on the Pro Mini) 61 | * 62 | * Midi panic on pin 11 and 12 (internal pullup, both pins low sends all notes off) 63 | * 64 | */ 65 | 66 | //_______________________________________________________________________________________________ DECLARATIONS 67 | 68 | #define ON_Thr 40 // Set threshold level before switching ON 69 | #define ON_Delay 20 // Set Delay after ON threshold before velocity is checked (wait for tounging peak) 70 | #define breath_max 300 // Blowing as hard as you can 71 | #define modsLo_Thr 411 // Low threshold for mod stick center 72 | #define modsHi_Thr 611 // High threshold for mod stick center 73 | #define octsLo_Thr 311 // Low threshold for octave stick center 74 | #define octsHi_Thr 711 // High threshold for octave stick center 75 | #define octsLo1_Thr 409 // Low threshold for octave select pot 76 | #define octsHi1_Thr 613 // High threshold for octave select pot 77 | #define octsLo2_Thr 205 // Low threshold 2 for octave select pot 78 | #define octsHi2_Thr 818 // High threshold 2 for octave select pot 79 | #define PB_sens 4095 // Pitch Bend sensitivity 0 to 8191 where 8191 is full pb range 80 | 81 | // The three states of our state machine 82 | 83 | // No note is sounding 84 | #define NOTE_OFF 1 85 | 86 | // We've observed a transition from below to above the 87 | // threshold value. We wait a while to see how fast the 88 | // breath velocity is increasing 89 | #define RISE_WAIT 2 90 | 91 | // A note is sounding 92 | #define NOTE_ON 3 93 | 94 | // Send CC data no more than every CC_INTERVAL 95 | // milliseconds 96 | #define CC_INTERVAL 15 97 | 98 | 99 | //variables setup 100 | 101 | int state; // The state of the state machine 102 | unsigned long ccSendTime = 0L; // The last time we sent CC values 103 | unsigned long breath_on_time = 0L; // Time when breath sensor value went over the ON threshold 104 | int initial_breath_value; // The breath value at the time we observed the transition 105 | 106 | long lastDebounceTime = 0; // The last time the fingering was changed 107 | long debounceDelay = 30; // The debounce time; increase if the output flickers 108 | int lastFingering = 0; // Keep the last fingering value for debouncing 109 | 110 | byte MIDIchannel=0; // MIDI channel 1 111 | 112 | int modLevel; 113 | int oldmod=0; 114 | 115 | int pitchBend; 116 | int oldpb=8192; 117 | 118 | int portLevel; 119 | int oldport=-1; 120 | 121 | int breathLevel=0; // breath level (smoothed) not mapped to CC value 122 | 123 | int pressureSensor; // pressure data from breath sensor, for midi breath cc and breath threshold checks 124 | byte velocity; // remapped midi velocity from breath sensor 125 | 126 | int fingeredNote; // note calculated from fingering (switches) and octave joystick position 127 | byte activeNote; // note playing 128 | byte startNote=72; // set startNote to C (change this value in steps of 12 to start in other octaves) 129 | 130 | byte midistatus=0; 131 | byte x; 132 | byte LedPin = 13; // select the pin for the LED 133 | 134 | Adafruit_MPR121 touchSensor = Adafruit_MPR121(); // This is the 12-input touch sensor 135 | 136 | // Key variables, TRUE (1) for pressed, FALSE (0) for not pressed 137 | byte K1; // First valve (pitch change -2) 138 | byte K2; // Second valve (pitch change -1) 139 | byte K3; // Third valve (pitch change -3) 140 | byte K4; // Cup key (pitch change -5) 141 | byte K5; // First trill key (pitch change +2) 142 | byte K6; // Second trill key (pitch change +1) 143 | byte K7; // Third trill key (pitch change +4) 144 | 145 | byte OCTup; // Octave switch key (pitch change +12) 146 | byte OCTdn; // Octave switch key (pitch change -12) 147 | 148 | byte PortK; // Portamento momentary on switch 149 | byte oldportk; 150 | 151 | int potOct; // Octave shifting by potentiometer (pitch change steps of 12) value from -2 to +2, 0 is center pos 152 | 153 | //_______________________________________________________________________________________________ SETUP 154 | 155 | void setup() { 156 | 157 | state = NOTE_OFF; // initialize state machine 158 | 159 | pinMode(LedPin,OUTPUT); // declare the LED's pin as output 160 | 161 | // joystick button for midi panic 162 | pinMode(11,INPUT_PULLUP); // panic pin 163 | 164 | // Set up touch sensor 165 | if (!touchSensor.begin(0x5A)) { 166 | while (1); // Touch sensor initialization failed - stop doing stuff 167 | } 168 | for (x=1; x<=4; x++){ // Do the flashy-flashy to say we are up and running 169 | digitalWrite( LedPin, HIGH ); 170 | delay(300); 171 | digitalWrite( LedPin, LOW ); 172 | delay(300); 173 | } 174 | 175 | Serial.begin(31250); // start serial with midi baudrate 31250 176 | Serial.flush(); 177 | } 178 | 179 | //_______________________________________________________________________________________________ MAIN LOOP 180 | 181 | void loop() { 182 | 183 | // if both joystick buttons are pressed, send all notes off 184 | if ((digitalRead(11) == 0) && (digitalRead(12) == 0)){ 185 | midiPanic(); 186 | } 187 | 188 | pressureSensor = analogRead(A3); // Get the pressure sensor reading from analog pin A3 189 | 190 | if (state == NOTE_OFF) { 191 | if (pressureSensor > ON_Thr) { 192 | // Value has risen above threshold. Move to the ON_Delay 193 | // state. Record time and initial breath value. 194 | breath_on_time = millis(); 195 | initial_breath_value = pressureSensor; 196 | state = RISE_WAIT; // Go to next state 197 | } 198 | } else if (state == RISE_WAIT) { 199 | if (pressureSensor > ON_Thr) { 200 | // Has enough time passed for us to collect our second 201 | // sample? 202 | if (millis() - breath_on_time > ON_Delay) { 203 | // Yes, so calculate MIDI note and velocity, then send a note on event 204 | readSwitches(); 205 | readOctaves(); 206 | oldportk=2; // Set oldportk to a value other than 1 or 0 to make sure it always sends the data for new notes 207 | portamento(); 208 | // We should be at tonguing peak, so set velocity based on current pressureSensor value 209 | // If initial value is greater than value after delay, go with initial value, constrain input to keep mapped output within 7 to 127 210 | velocity = map(constrain(max(pressureSensor,initial_breath_value),ON_Thr,breath_max),ON_Thr,breath_max,7,127); 211 | breathLevel=constrain(max(pressureSensor,initial_breath_value),ON_Thr,breath_max); 212 | midiSend((0x90 | MIDIchannel), fingeredNote, velocity); // send Note On message for new note 213 | activeNote=fingeredNote; 214 | state = NOTE_ON; 215 | } 216 | } else { 217 | // Value fell below threshold before ON_Delay passed. Return to 218 | // NOTE_OFF state (e.g. we're ignoring a short blip of breath) 219 | state = NOTE_OFF; 220 | } 221 | } else if (state == NOTE_ON) { 222 | if (pressureSensor < ON_Thr) { 223 | // Value has fallen below threshold - turn the note off 224 | midiSend((0x80 | MIDIchannel), activeNote, velocity); // send Note Off message 225 | breathLevel=0; 226 | state = NOTE_OFF; 227 | } else { 228 | // Is it time to send more CC data? 229 | if (millis() - ccSendTime > CC_INTERVAL) { 230 | // deal with Breath, Pitch Bend, Modulation and Portamento 231 | breath(); 232 | pitch_bend(); 233 | modulation(); 234 | ccSendTime = millis(); 235 | } 236 | readSwitches(); 237 | readOctaves(); 238 | if (fingeredNote != lastFingering){ // 239 | // reset the debouncing timer 240 | lastDebounceTime = millis(); 241 | } 242 | if ((millis() - lastDebounceTime) > debounceDelay) { 243 | // whatever the reading is at, it's been there for longer 244 | // than the debounce delay, so take it as the actual current state 245 | if (fingeredNote != activeNote) { 246 | // Player has moved to a new fingering while still blowing. 247 | // Send a note off for the current note and a note on for 248 | // the new note. 249 | portamento(); 250 | velocity = map(constrain(pressureSensor,ON_Thr,breath_max),ON_Thr,breath_max,7,127); // set new velocity value based on current pressure sensor level 251 | midiSend((0x90 | MIDIchannel), fingeredNote, velocity); // send Note On message for new note 252 | midiSend((0x80 | MIDIchannel), activeNote, 0); // send Note Off message for previous note (legato) 253 | activeNote=fingeredNote; 254 | } 255 | } 256 | } 257 | } 258 | lastFingering=fingeredNote; 259 | } 260 | //_______________________________________________________________________________________________ FUNCTIONS 261 | 262 | // Send a three byte midi message 263 | void midiSend(byte midistatus, byte data1, byte data2) { 264 | digitalWrite(LedPin,HIGH); // indicate we're sending MIDI data 265 | Serial.write(midistatus); 266 | Serial.write(data1); 267 | Serial.write(data2); 268 | digitalWrite(LedPin,LOW); // indicate we're sending MIDI data 269 | } 270 | 271 | //************************************************************** 272 | 273 | void midiPanic(){ 274 | for (int i = 0; i < 128; i++){ 275 | midiSend((0x80 | MIDIchannel), i, 0); 276 | } 277 | } 278 | 279 | //************************************************************** 280 | 281 | void pitch_bend(){ 282 | int pitchLSB; 283 | int pitchMSB; 284 | pitchBend = analogRead(A0); // read voltage on analog pin A0 285 | if (pitchBend > modsHi_Thr){ 286 | pitchBend = map(pitchBend,modsHi_Thr,1023,8192,(8192 + PB_sens)); // go from 8192 to 16383 (full pb up) when off center threshold going up 287 | } else if (pitchBend < modsLo_Thr){ 288 | pitchBend = map(pitchBend,0,modsLo_Thr,(8191 - PB_sens),8192); // go from 8192 to 0 (full pb dn) when off center threshold going down 289 | } else { 290 | pitchBend = 8192; // 8192 is 0 pitch bend 291 | } 292 | if (pitchBend != oldpb){// only send midi data if pitch bend has changed from previous value 293 | pitchLSB = pitchBend & 0x007F; 294 | pitchMSB = (pitchBend >>7) & 0x007F; 295 | midiSend((0xE0 | MIDIchannel), pitchLSB, pitchMSB); 296 | oldpb=pitchBend; 297 | } 298 | } 299 | 300 | //*********************************************************** 301 | 302 | void modulation(){ 303 | modLevel = analogRead(A1); // read voltage on analog pin A1 304 | if (modLevel > modsHi_Thr){ 305 | modLevel = map(modLevel,modsHi_Thr,1023,0,127); // go from 0 to full modulation when off center threshold going right(?) 306 | } else if (modLevel < modsLo_Thr){ 307 | modLevel = map(modLevel,0,modsLo_Thr,127,0); // go from 0 to full modulation when off center threshold going left(?) 308 | } else { 309 | modLevel = 0; // zero modulation in center position 310 | } 311 | if (modLevel != oldmod){ // only send midi data if modulation has changed from previous value 312 | midiSend((0xB0 | MIDIchannel), 1, modLevel); 313 | oldmod=modLevel; 314 | } 315 | } 316 | 317 | //*********************************************************** 318 | 319 | void portamento(){ 320 | portLevel = map(analogRead(A2),0,1023,0,127); // read voltage on analog pin A7 and map to midi value 321 | if (portLevel != oldport){ // only send midi data if level has changed from previous value 322 | midiSend((0xB0 | MIDIchannel), 5, portLevel); 323 | oldport=portLevel; 324 | } 325 | if (PortK != oldportk){ // only send midi data if status has changed from previous value 326 | if (PortK){ 327 | midiSend((0xB0 | MIDIchannel), 65, 127); // send portamento on 328 | } 329 | else { 330 | midiSend((0xB0 | MIDIchannel), 65, 0); // send portamento off 331 | } 332 | oldportk=PortK; 333 | } 334 | } 335 | 336 | //*********************************************************** 337 | 338 | void breath(){ 339 | int breathCC; 340 | breathLevel = breathLevel*0.8+pressureSensor*0.2; // smoothing of breathLevel value 341 | breathCC = map(constrain(breathLevel,ON_Thr,breath_max),ON_Thr,breath_max,0,127); 342 | midiSend((0xB0 | MIDIchannel), 2, breathCC); 343 | } 344 | //*********************************************************** 345 | 346 | void readOctaves(){ 347 | // Read octave select pot to shift octave -2 to +2 348 | int octaveReading; 349 | int joyOctaveR; 350 | octaveReading = analogRead(A6); // read voltage on analog pin A6 351 | joyOctaveR = analogRead(A7); // read voltage on analog pin A7 352 | potOct = 0; 353 | if (octaveReading > octsHi1_Thr) { 354 | potOct++; 355 | } 356 | if (octaveReading < octsLo1_Thr) { 357 | potOct--; 358 | } 359 | if (octaveReading > octsHi2_Thr) { 360 | potOct++; 361 | } 362 | if (octaveReading < octsLo2_Thr) { 363 | potOct--; 364 | } 365 | if (joyOctaveR > octsHi_Thr) { 366 | potOct++; 367 | } 368 | if (joyOctaveR < octsLo_Thr) { 369 | potOct--; 370 | } 371 | //calculate midi note number from octave shift 372 | fingeredNote=fingeredNote+potOct*12; 373 | } 374 | //*********************************************************** 375 | 376 | void readSwitches(){ 377 | // Read switches and put value in variables 378 | uint16_t touchValue = touchSensor.touched(); 379 | K1=((touchValue >> 0) & 0x01); 380 | K2=((touchValue >> 1) & 0x01); 381 | K3=((touchValue >> 2) & 0x01); 382 | K4=((touchValue >> 3) & 0x01); 383 | K5=((touchValue >> 4) & 0x01); 384 | K6=((touchValue >> 5) & 0x01); 385 | K7=((touchValue >> 6) & 0x01); 386 | OCTup=((touchValue >> 7) & 0x01); // keep this? 387 | OCTdn=((touchValue >> 8) & 0x01); // keep this? 388 | PortK=((touchValue >> 9) & 0x01); // portamento key 389 | //calculate midi note number from pressed keys 390 | fingeredNote=startNote-2*K1-K2-3*K3-5*K4+2*K5+K6+4*K7+12*OCTup-12*OCTdn; 391 | } 392 | -------------------------------------------------------------------------------- /MiniVI-cap/evi1000.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trasselfrisyr/MiniWI/539163e4f242e2ff6e4cc9de6d08df4fdd62859f/MiniVI-cap/evi1000.pdf -------------------------------------------------------------------------------- /MiniWI-cap-pmt-ArcoreProMicro/MiniWI-cap-pmt-ArcoreProMicro.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | //Requires the Arcore arduino core 4 | 5 | /* 6 | NAME: MiniWI Cap Touch and Portamento ver. 7 | WRITTEN BY: JOHAN BERGLUND 8 | CREDITS: State machine from the Gordophone blog by GORDON GOOD 9 | DATE: 2016-06-01 10 | FILE SAVED AS: MiniWI-cap-pmt-ArcoreProMicro.ino 11 | FOR: Arduino Pro Micro, ATmega32U4 12 | CLOCK: 16.00 MHz 13 | PROGRAMME FUNCTION: Wind Controller with EWI style key setup (reduced) with optional Casio DH addition, 14 | Freescale MPX5010GP breath sensor, PS2 style thumb joysticks 15 | for octave selection and pb/mod control, capacitive touch keys, output to 5-pin DIN MIDI 16 | and USB MIDI 17 | 18 | HARDWARE NOTES: 19 | * For the MIDI connection, attach a MIDI out Female 180 Degree 5-Pin DIN socket to Arduino. 20 | * Socket is seen from solder tags at rear. 21 | * DIN-5 pinout is: _______ 22 | * pin 2 - GND / \ 23 | * pin 4 - 220 ohm resistor to +5V | 1 3 | MIDI jack 24 | * pin 5 - Arduino Pin 1 (TX) via a 220 ohm resistor | 4 5 | 25 | * all other pins - unconnected \___2___/ 26 | * 27 | * Left hand thumb joystick controls octaves. 28 | * Up/down axis is connected to Arduino pin A6. 29 | * 30 | * +1 31 | * ^ 32 | * < o > 33 | * v 34 | * -1 35 | * 36 | * A potentiometer connected to Arduino pin A7 sets the base octave -2 to +2 from startnote octave. 37 | * 38 | * Right hand thumb joystick controls pitch bend and modulation. 39 | * Pitch bend and modulation are connected to Arduino pins A0 and A1, 40 | * on DIP rows. 41 | * 42 | * PB up 43 | * ^ 44 | * Mod < o > Mod 45 | * v 46 | * PB dn 47 | * 48 | * A potentiometer controls portamento speed setting. 49 | * It is connected to Arduino pin A2. 50 | * 51 | * The Freescale MPX5010GP pressure sensor output (V OUT) is connected to Arduino pin A3. 52 | * 53 | * Sensor pinout 54 | * 1: V OUT (pin with indent) 55 | * 2: GND 56 | * 3: VCC (to 5V) 57 | * 4: n/c 58 | * 5: n/c 59 | * 6: n/c 60 | * 61 | * 62 | * Adafruit MPR121 board connected to Arduino I2C ports (A4-SDA and A5-SCL on the Pro Mini) 63 | * Touch keys including portamento key connected to MPR121 board. 64 | * 65 | * Midi panic on pin 11 and 12 (internal pullup, both pins low sends all notes off) 66 | * 67 | */ 68 | 69 | //_______________________________________________________________________________________________ DECLARATIONS 70 | 71 | #define ON_Thr 40 // Set threshold level before switching ON 72 | #define ON_Delay 20 // Set Delay after ON threshold before velocity is checked (wait for tounging peak) 73 | #define breath_max 300 // Blowing as hard as you can 74 | #define modsLo_Thr 411 // Low threshold for mod stick center 75 | #define modsHi_Thr 611 // High threshold for mod stick center 76 | #define octsLo_Thr 311 // Low threshold for octave stick center 77 | #define octsHi_Thr 711 // High threshold for octave stick center 78 | #define octsLo1_Thr 409 // Low threshold for octave select pot 79 | #define octsHi1_Thr 613 // High threshold for octave select pot 80 | #define octsLo2_Thr 205 // Low threshold 2 for octave select pot 81 | #define octsHi2_Thr 818 // High threshold 2 for octave select pot 82 | #define PB_sens 4095 // Pitch Bend sensitivity 0 to 8191 where 8191 is full pb range 83 | #define casioMod 0 // Default selection on/off for Casio DH 2nd octave fingering (LH1 lifted) 84 | 85 | // The three states of our state machine 86 | 87 | // No note is sounding 88 | #define NOTE_OFF 1 89 | 90 | // We've observed a transition from below to above the 91 | // threshold value. We wait a while to see how fast the 92 | // breath velocity is increasing 93 | #define RISE_WAIT 2 94 | 95 | // A note is sounding 96 | #define NOTE_ON 3 97 | 98 | // Send CC data no more than every CC_INTERVAL 99 | // milliseconds 100 | #define CC_INTERVAL 15 101 | 102 | 103 | //variables setup 104 | 105 | byte casiomodSelect; // Change the fingering setting w octave stick up at power on 106 | 107 | int state; // The state of the state machine 108 | unsigned long ccSendTime = 0L; // The last time we sent CC values 109 | unsigned long breath_on_time = 0L; // Time when breath sensor value went over the ON threshold 110 | int initial_breath_value; // The breath value at the time we observed the transition 111 | 112 | long lastDebounceTime = 0; // The last time the fingering was changed 113 | long debounceDelay = 30; // The debounce time; increase if the output flickers 114 | int lastFingering = 0; // Keep the last fingering value for debouncing 115 | 116 | byte MIDIchannel=0; // MIDI channel 1 117 | 118 | int modLevel; 119 | int oldmod=0; 120 | 121 | int pitchBend; 122 | int oldpb=8192; 123 | 124 | int portLevel; 125 | int oldport=-1; 126 | 127 | int breathLevel=0; // breath level (smoothed) not mapped to CC value 128 | 129 | int pressureSensor; // pressure data from breath sensor, for midi breath cc and breath threshold checks 130 | byte velocity; // remapped midi velocity from breath sensor 131 | 132 | int fingeredNote; // note calculated from fingering (switches) and octave joystick position 133 | byte activeNote; // note playing 134 | byte startNote=73; // set startNote to C# (change this value in steps of 12 to start in other octaves) 135 | 136 | byte midistatus=0; 137 | byte x; 138 | byte LedPin = 13; // select the pin for the LED 139 | 140 | Adafruit_MPR121 touchSensor = Adafruit_MPR121(); // This is the 12-input touch sensor 141 | 142 | // Key variables, TRUE (1) for pressed, FALSE (0) for not pressed 143 | byte LH1; // Left Hand key 1 (pitch change -2) 144 | // Casio mod addition: If LH1 is not touched when LH2 and LH3 are, pitch change +9 145 | byte LHb; // Left Hand bis key (pitch change -1 unless both LH1 and LH2 are pressed) 146 | // Casio modification: pitch change -1 unless LH2 is pressed 147 | byte LH2; // Left Hand key 2 (with LH1 also pressed pitch change is -2, otherwise -1) 148 | byte LH3; // Left Hand key 3 (pitch change -2) 149 | byte LHp1; // Left Hand pinky key 1 (pitch change +1) 150 | byte LHp2=0; // Left Hand pinky key 2 (pitch change -1) --- Not used in this version 151 | byte RHs=0; // Right Hand side key (pitch change -2 unless LHp1 is pressed) --- Not used in this version 152 | byte RH1; // Right Hand key 1 (with LH3 also pressed pitch change is -2, otherwise -1) 153 | byte RH2; // Right Hand key 2 (pitch change -1) 154 | byte RH3; // Right Hand key 3 (pitch change -2) 155 | byte RHp1=0; // Right Hand pinky key 1 (pitch change +1) --- Not used in this version 156 | byte RHp2; // Right Hand pinky key 2 (pitch change -1) 157 | byte RHp3; // Right Hand pinky key 3 (pitch change -2) 158 | byte OCTup=0; // Octave switch key (pitch change +12) --- Not used in this version 159 | byte OCTdn=0; // Octave switch key (pitch change -12) --- Not used in this version 160 | 161 | byte PortK; // Portamento momentary on switch 162 | byte oldportk; 163 | 164 | int joyOct; // Octave shifting by joystick or potentiometer 165 | 166 | //_______________________________________________________________________________________________ SETUP 167 | 168 | void setup() { 169 | 170 | state = NOTE_OFF; // initialize state machine 171 | 172 | pinMode(LedPin,OUTPUT); // declare the LED's pin as output 173 | 174 | // joystick buttons for midi panic 175 | pinMode(16,INPUT_PULLUP); // panic pin 1/2 176 | pinMode(14,INPUT_PULLUP); // panic pin 2/2 177 | 178 | // Set up touch sensor 179 | if (!touchSensor.begin(0x5A)) { 180 | while (1); // Touch sensor initialization failed - stop doing stuff 181 | } 182 | // Set the selection for Casio fingering - Pitch stick up at power on changes from default 183 | if (analogRead(A6) > octsHi_Thr) { 184 | casiomodSelect=!casioMod; 185 | } else{ 186 | casiomodSelect=casioMod; 187 | } 188 | for (x=1; x<=4; x++){ // Do the flashy-flashy to say we are up and running 189 | digitalWrite( LedPin, HIGH ); 190 | delay(300); 191 | digitalWrite( LedPin, LOW ); 192 | delay(300); 193 | } 194 | 195 | Serial.begin(31250); // start serial with midi baudrate 31250 196 | Serial.flush(); 197 | } 198 | 199 | //_______________________________________________________________________________________________ MAIN LOOP 200 | 201 | void loop() { 202 | 203 | // if both joystick buttons are pressed, send all notes off 204 | if ((digitalRead(16) == 0) && (digitalRead(14) == 0)){ 205 | midiPanic(); 206 | } 207 | 208 | pressureSensor = analogRead(A3); // Get the pressure sensor reading from analog pin A3 209 | 210 | if (state == NOTE_OFF) { 211 | if (pressureSensor > ON_Thr) { 212 | // Value has risen above threshold. Move to the ON_Delay 213 | // state. Record time and initial breath value. 214 | breath_on_time = millis(); 215 | initial_breath_value = pressureSensor; 216 | state = RISE_WAIT; // Go to next state 217 | } 218 | } else if (state == RISE_WAIT) { 219 | if (pressureSensor > ON_Thr) { 220 | // Has enough time passed for us to collect our second 221 | // sample? 222 | if (millis() - breath_on_time > ON_Delay) { 223 | // Yes, so calculate MIDI note and velocity, then send a note on event 224 | readSwitches(); 225 | readOctaves(); 226 | oldportk=2; // Set oldportk to a value other than 1 or 0 to make sure it always sends the data for new notes 227 | portamento(); 228 | // We should be at tonguing peak, so set velocity based on current pressureSensor value 229 | // If initial value is greater than value after delay, go with initial value, constrain input to keep mapped output within 7 to 127 230 | velocity = map(constrain(max(pressureSensor,initial_breath_value),ON_Thr,breath_max),ON_Thr,breath_max,7,127); 231 | breathLevel=constrain(max(pressureSensor,initial_breath_value),ON_Thr,breath_max); 232 | breath(); 233 | midiSend((0x90 | MIDIchannel), fingeredNote, velocity); // send Note On message for new note 234 | noteOn(MIDIchannel, fingeredNote, velocity); 235 | activeNote=fingeredNote; 236 | state = NOTE_ON; 237 | } 238 | } else { 239 | // Value fell below threshold before ON_Delay passed. Return to 240 | // NOTE_OFF state (e.g. we're ignoring a short blip of breath) 241 | state = NOTE_OFF; 242 | } 243 | } else if (state == NOTE_ON) { 244 | if (pressureSensor < ON_Thr) { 245 | // Value has fallen below threshold - turn the note off 246 | midiSend((0x80 | MIDIchannel), activeNote, velocity); // send Note Off message 247 | noteOff(MIDIchannel, activeNote, velocity); 248 | breathLevel=0; 249 | state = NOTE_OFF; 250 | } else { 251 | // Is it time to send more CC data? 252 | if (millis() - ccSendTime > CC_INTERVAL) { 253 | // deal with Breath, Pitch Bend and Modulation 254 | breath(); 255 | pitch_bend(); 256 | modulation(); 257 | ccSendTime = millis(); 258 | } 259 | readSwitches(); 260 | readOctaves(); 261 | if (fingeredNote != lastFingering){ // 262 | // reset the debouncing timer 263 | lastDebounceTime = millis(); 264 | } 265 | if ((millis() - lastDebounceTime) > debounceDelay) { 266 | // whatever the reading is at, it's been there for longer 267 | // than the debounce delay, so take it as the actual current state 268 | if (fingeredNote != activeNote) { 269 | // Player has moved to a new fingering while still blowing. 270 | // Send a note off for the current note and a note on for 271 | // the new note. 272 | portamento(); 273 | velocity = map(constrain(pressureSensor,ON_Thr,breath_max),ON_Thr,breath_max,7,127); // set new velocity value based on current pressure sensor level 274 | midiSend((0x90 | MIDIchannel), fingeredNote, velocity); // send Note On message for new note 275 | noteOn(MIDIchannel, fingeredNote, velocity); 276 | midiSend((0x80 | MIDIchannel), activeNote, 0); // send Note Off message for previous note (legato) 277 | noteOff(MIDIchannel, activeNote, 0); 278 | activeNote=fingeredNote; 279 | } 280 | } 281 | } 282 | } 283 | lastFingering=fingeredNote; 284 | } 285 | //_______________________________________________________________________________________________ FUNCTIONS 286 | 287 | // Send a three byte midi message 288 | void midiSend(byte midistatus, byte data1, byte data2) { 289 | digitalWrite(LedPin,HIGH); // indicate we're sending MIDI data 290 | Serial.write(midistatus); 291 | Serial.write(data1); 292 | Serial.write(data2); 293 | digitalWrite(LedPin,LOW); // indicate we're sending MIDI data 294 | } 295 | 296 | //************************************************************** 297 | 298 | void midiPanic(){ 299 | for (int i = 0; i < 128; i++){ 300 | midiSend((0x80 | MIDIchannel), i, 0); 301 | noteOff(MIDIchannel, i, 0); 302 | } 303 | } 304 | 305 | //************************************************************** 306 | 307 | void pitch_bend(){ 308 | int pitchLSB; 309 | int pitchMSB; 310 | pitchBend = analogRead(A0); // read voltage on analog pin A0 311 | if (pitchBend > modsHi_Thr){ 312 | pitchBend = map(pitchBend,modsHi_Thr,1023,8192,(8192 + PB_sens)); // go from 8192 to 16383 (full pb up) when off center threshold going up 313 | } else if (pitchBend < modsLo_Thr){ 314 | pitchBend = map(pitchBend,0,modsLo_Thr,(8191 - PB_sens),8192); // go from 8192 to 0 (full pb dn) when off center threshold going down 315 | } else { 316 | pitchBend = 8192; // 8192 is 0 pitch bend 317 | } 318 | if (pitchBend != oldpb){// only send midi data if pitch bend has changed from previous value 319 | pitchLSB = pitchBend & 0x007F; 320 | pitchMSB = (pitchBend >>7) & 0x007F; 321 | midiSend((0xE0 | MIDIchannel), pitchLSB, pitchMSB); 322 | pitchBendChange(MIDIchannel, pitchBend); 323 | oldpb=pitchBend; 324 | } 325 | } 326 | 327 | //*********************************************************** 328 | 329 | void modulation(){ 330 | modLevel = analogRead(A1); // read voltage on analog pin A1 331 | if (modLevel > modsHi_Thr){ 332 | modLevel = map(modLevel,modsHi_Thr,1023,0,127); // go from 0 to full modulation when off center threshold going right(?) 333 | } else if (modLevel < modsLo_Thr){ 334 | modLevel = map(modLevel,0,modsLo_Thr,127,0); // go from 0 to full modulation when off center threshold going left(?) 335 | } else { 336 | modLevel = 0; // zero modulation in center position 337 | } 338 | if (modLevel != oldmod){ // only send midi data if modulation has changed from previous value 339 | midiSend((0xB0 | MIDIchannel), 1, modLevel); 340 | controlChange(MIDIchannel, 1, modLevel); 341 | oldmod=modLevel; 342 | } 343 | } 344 | 345 | //*********************************************************** 346 | 347 | void portamento(){ 348 | portLevel = map(analogRead(A2),0,1023,0,127); // read voltage on analog pin A7 and map to midi value 349 | if (portLevel != oldport){ // only send midi data if level has changed from previous value 350 | midiSend((0xB0 | MIDIchannel), 5, portLevel); 351 | controlChange(MIDIchannel, 5, portLevel); 352 | oldport=portLevel; 353 | } 354 | if (PortK != oldportk){ // only send midi data if status has changed from previous value 355 | if (PortK){ 356 | midiSend((0xB0 | MIDIchannel), 65, 127); // send portamento on 357 | controlChange(MIDIchannel, 65, 127); 358 | } 359 | else { 360 | midiSend((0xB0 | MIDIchannel), 65, 0); // send portamento off 361 | controlChange(MIDIchannel, 65, 0); 362 | } 363 | oldportk=PortK; 364 | } 365 | } 366 | 367 | //*********************************************************** 368 | 369 | void breath(){ 370 | int breathCC; 371 | breathLevel = breathLevel*0.8+pressureSensor*0.2; // smoothing of breathLevel value 372 | breathCC = map(constrain(breathLevel,ON_Thr,breath_max),ON_Thr,breath_max,0,127); 373 | midiSend((0xB0 | MIDIchannel), 2, breathCC); 374 | controlChange(MIDIchannel, 2, breathCC); 375 | } 376 | //*********************************************************** 377 | 378 | void readOctaves(){ 379 | // Read octave joystick and set octave of the fingered note (run after readSwitches) 380 | int xOctaves; 381 | int yOctaves; 382 | xOctaves = analogRead(A6); // read voltage on analog pin A6 383 | yOctaves = analogRead(A7); // read voltage on analog pin A7 (this is now a separate potentiometer, not joystick axis) 384 | joyOct = 0; 385 | // xOctaves is up/down and the only used octave joystick direction in this version 386 | if (xOctaves > octsHi_Thr) { 387 | joyOct++; 388 | } else if (xOctaves < octsLo_Thr) { 389 | joyOct--; 390 | } 391 | // yOctaves in this version is a separate potentiometer setting base octave -2 to +2 392 | if (yOctaves > octsHi1_Thr) { 393 | joyOct++; // ++ or -- depending on joystick orientation 394 | } else if (yOctaves < octsLo1_Thr) { 395 | joyOct--; // ++ or -- depending on joystick orientation 396 | } 397 | if (yOctaves > octsHi2_Thr) { 398 | joyOct++; // ++ or -- depending on joystick orientation 399 | } else if (yOctaves < octsLo2_Thr) { 400 | joyOct--; // ++ or -- depending on joystick orientation 401 | } 402 | //calculate midi note number from octave shifts 403 | fingeredNote=fingeredNote+joyOct*12; 404 | } 405 | //*********************************************************** 406 | 407 | void readSwitches(){ 408 | // Read switches and put value in variables 409 | uint16_t touchValue = touchSensor.touched(); 410 | LH1=((touchValue >> 0) & 0x01); 411 | LHb=((touchValue >> 1) & 0x01); 412 | LH2=((touchValue >> 2) & 0x01); 413 | LH3=((touchValue >> 3) & 0x01); 414 | LHp1=((touchValue >> 4) & 0x01); 415 | RH1=((touchValue >> 6) & 0x01); 416 | RH2=((touchValue >> 7) & 0x01); 417 | RH3=((touchValue >> 8) & 0x01); 418 | RHp2=((touchValue >> 9) & 0x01); 419 | RHp3=((touchValue >> 10) & 0x01); 420 | PortK=((touchValue >> 5) & 0x01); // portamento key 421 | //calculate midi note number from pressed keys 422 | if (casiomodSelect){ 423 | fingeredNote=startNote-2*LH1-(LHb && !LH2)-LH2-(LH2 && LH1)-2*LH3+LHp1-LHp2+(RHs && !LHp1)-RH1-(RH1 && LH3)-RH2-2*RH3+RHp1-RHp2-2*RHp3+12*OCTup-12*OCTdn+9*(!LH1 && LH2 && LH3); 424 | } else { 425 | fingeredNote=startNote-2*LH1-(LHb && !(LH1 && LH2))-LH2-(LH2 && LH1)-2*LH3+LHp1-LHp2+(RHs && !LHp1)-RH1-(RH1 && LH3)-RH2-2*RH3+RHp1-RHp2-2*RHp3+12*OCTup-12*OCTdn; 426 | } 427 | } 428 | 429 | //*********************************************************** 430 | // Arcore MIDI functions 431 | 432 | void controlChange(byte channel, byte control, byte value) { 433 | MIDIEvent event = {0x0B, 0xB0 | channel, control, value}; 434 | MIDIUSB.write(event); 435 | } 436 | 437 | void channelAT(byte channel, byte value) { 438 | MIDIEvent event = {0x0D, 0xD0 | channel, value}; 439 | MIDIUSB.write(event); 440 | } 441 | 442 | void noteOn(byte channel, byte pitch, byte velocity) { 443 | MIDIEvent noteOn = {0x09, 0x90 | channel, pitch, velocity}; 444 | MIDIUSB.write(noteOn); 445 | } 446 | 447 | void noteOff(byte channel, byte pitch, byte velocity) { 448 | MIDIEvent noteOff = {0x08, 0x80 | channel, pitch, velocity}; 449 | MIDIUSB.write(noteOff); 450 | } 451 | 452 | void pitchBendChange(byte channel, int value) { 453 | byte lowValue = value & 0x7F; 454 | byte highValue = value >> 7; 455 | MIDIEvent event = {0x0E, 0xE0 | channel, lowValue, highValue}; 456 | MIDIUSB.write(event); 457 | } 458 | -------------------------------------------------------------------------------- /MiniWI-cap-pmt/MiniWI-cap-pmt-fingering-casiomod.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trasselfrisyr/MiniWI/539163e4f242e2ff6e4cc9de6d08df4fdd62859f/MiniWI-cap-pmt/MiniWI-cap-pmt-fingering-casiomod.png -------------------------------------------------------------------------------- /MiniWI-cap-pmt/MiniWI-cap-pmt-schematic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trasselfrisyr/MiniWI/539163e4f242e2ff6e4cc9de6d08df4fdd62859f/MiniWI-cap-pmt/MiniWI-cap-pmt-schematic.png -------------------------------------------------------------------------------- /MiniWI-cap-pmt/MiniWI-cap-pmt.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /* 5 | NAME: MiniWI Cap Touch and Portamento ver. 6 | WRITTEN BY: JOHAN BERGLUND 7 | CREDITS: State machine from the Gordophone blog by GORDON GOOD 8 | DATE: 2016-06-01 9 | FILE SAVED AS: MiniWI-cap-pmt.ino 10 | FOR: Arduino Pro Mini, ATmega328, version with breakouts for A6 and A7 11 | CLOCK: 16.00 MHz CRYSTAL 12 | PROGRAMME FUNCTION: Wind Controller with EWI style key setup (reduced) with optional Casio DH addition, 13 | Freescale MPX5010GP breath sensor, PS2 style thumb joysticks 14 | for octave selection and pb/mod control, capacitive touch keys, output to 5-pin DIN MIDI 15 | 16 | HARDWARE NOTES: 17 | * For the MIDI connection, attach a MIDI out Female 180 Degree 5-Pin DIN socket to Arduino. 18 | * Socket is seen from solder tags at rear. 19 | * DIN-5 pinout is: _______ 20 | * pin 2 - GND / \ 21 | * pin 4 - 220 ohm resistor to +5V | 1 3 | MIDI jack 22 | * pin 5 - Arduino Pin 1 (TX) via a 220 ohm resistor | 4 5 | 23 | * all other pins - unconnected \___2___/ 24 | * 25 | * Left hand thumb joystick controls octaves. 26 | * Up/down axis is connected to Arduino pin A6. 27 | * 28 | * +1 29 | * ^ 30 | * < o > 31 | * v 32 | * -1 33 | * 34 | * A potentiometer connected to Arduino pin A7 sets the base octave -2 to +2 from startnote octave. 35 | * 36 | * Right hand thumb joystick controls pitch bend and modulation. 37 | * Pitch bend and modulation are connected to Arduino pins A0 and A1, 38 | * on DIP rows. 39 | * 40 | * PB up 41 | * ^ 42 | * Mod < o > Mod 43 | * v 44 | * PB dn 45 | * 46 | * A potentiometer controls portamento speed setting. 47 | * It is connected to Arduino pin A2. 48 | * 49 | * The Freescale MPX5010GP pressure sensor output (V OUT) is connected to Arduino pin A3. 50 | * 51 | * Sensor pinout 52 | * 1: V OUT (pin with indent) 53 | * 2: GND 54 | * 3: VCC (to 5V) 55 | * 4: n/c 56 | * 5: n/c 57 | * 6: n/c 58 | * 59 | * 60 | * Adafruit MPR121 board connected to Arduino I2C ports (A4-SDA and A5-SCL on the Pro Mini) 61 | * Touch keys including portamento key connected to MPR121 board. 62 | * 63 | * Midi panic on pin 11 and 12 (internal pullup, both pins low sends all notes off) 64 | * 65 | */ 66 | 67 | //_______________________________________________________________________________________________ DECLARATIONS 68 | 69 | #define ON_Thr 40 // Set threshold level before switching ON 70 | #define ON_Delay 20 // Set Delay after ON threshold before velocity is checked (wait for tounging peak) 71 | #define breath_max 300 // Blowing as hard as you can 72 | #define modsLo_Thr 411 // Low threshold for mod stick center 73 | #define modsHi_Thr 611 // High threshold for mod stick center 74 | #define octsLo_Thr 311 // Low threshold for octave stick center 75 | #define octsHi_Thr 711 // High threshold for octave stick center 76 | #define octsLo1_Thr 409 // Low threshold for octave select pot 77 | #define octsHi1_Thr 613 // High threshold for octave select pot 78 | #define octsLo2_Thr 205 // Low threshold 2 for octave select pot 79 | #define octsHi2_Thr 818 // High threshold 2 for octave select pot 80 | #define PB_sens 4095 // Pitch Bend sensitivity 0 to 8191 where 8191 is full pb range 81 | #define casioMod 0 // Default selection on/off for Casio DH 2nd octave fingering (LH1 lifted) 82 | 83 | // The three states of our state machine 84 | 85 | // No note is sounding 86 | #define NOTE_OFF 1 87 | 88 | // We've observed a transition from below to above the 89 | // threshold value. We wait a while to see how fast the 90 | // breath velocity is increasing 91 | #define RISE_WAIT 2 92 | 93 | // A note is sounding 94 | #define NOTE_ON 3 95 | 96 | // Send CC data no more than every CC_INTERVAL 97 | // milliseconds 98 | #define CC_INTERVAL 15 99 | 100 | 101 | //variables setup 102 | 103 | byte casiomodSelect; // Change the fingering setting w octave stick up at power on 104 | 105 | int state; // The state of the state machine 106 | unsigned long ccSendTime = 0L; // The last time we sent CC values 107 | unsigned long breath_on_time = 0L; // Time when breath sensor value went over the ON threshold 108 | int initial_breath_value; // The breath value at the time we observed the transition 109 | 110 | long lastDebounceTime = 0; // The last time the fingering was changed 111 | long debounceDelay = 30; // The debounce time; increase if the output flickers 112 | int lastFingering = 0; // Keep the last fingering value for debouncing 113 | 114 | byte MIDIchannel=0; // MIDI channel 1 115 | 116 | int modLevel; 117 | int oldmod=0; 118 | 119 | int pitchBend; 120 | int oldpb=8192; 121 | 122 | int portLevel; 123 | int oldport=-1; 124 | 125 | int breathLevel=0; // breath level (smoothed) not mapped to CC value 126 | 127 | int pressureSensor; // pressure data from breath sensor, for midi breath cc and breath threshold checks 128 | byte velocity; // remapped midi velocity from breath sensor 129 | 130 | int fingeredNote; // note calculated from fingering (switches) and octave joystick position 131 | byte activeNote; // note playing 132 | byte startNote=73; // set startNote to C# (change this value in steps of 12 to start in other octaves) 133 | 134 | byte midistatus=0; 135 | byte x; 136 | byte LedPin = 13; // select the pin for the LED 137 | 138 | Adafruit_MPR121 touchSensor = Adafruit_MPR121(); // This is the 12-input touch sensor 139 | 140 | // Key variables, TRUE (1) for pressed, FALSE (0) for not pressed 141 | byte LH1; // Left Hand key 1 (pitch change -2) 142 | // Casio mod addition: If LH1 is not touched when LH2 and LH3 are, pitch change +9 143 | byte LHb; // Left Hand bis key (pitch change -1 unless both LH1 and LH2 are pressed) 144 | // Casio modification: pitch change -1 unless LH2 is pressed 145 | byte LH2; // Left Hand key 2 (with LH1 also pressed pitch change is -2, otherwise -1) 146 | byte LH3; // Left Hand key 3 (pitch change -2) 147 | byte LHp1; // Left Hand pinky key 1 (pitch change +1) 148 | byte LHp2=0; // Left Hand pinky key 2 (pitch change -1) --- Not used in this version 149 | byte RHs=0; // Right Hand side key (pitch change -2 unless LHp1 is pressed) --- Not used in this version 150 | byte RH1; // Right Hand key 1 (with LH3 also pressed pitch change is -2, otherwise -1) 151 | byte RH2; // Right Hand key 2 (pitch change -1) 152 | byte RH3; // Right Hand key 3 (pitch change -2) 153 | byte RHp1=0; // Right Hand pinky key 1 (pitch change +1) --- Not used in this version 154 | byte RHp2; // Right Hand pinky key 2 (pitch change -1) 155 | byte RHp3; // Right Hand pinky key 3 (pitch change -2) 156 | byte OCTup=0; // Octave switch key (pitch change +12) --- Not used in this version 157 | byte OCTdn=0; // Octave switch key (pitch change -12) --- Not used in this version 158 | 159 | byte PortK; // Portamento momentary on switch 160 | byte oldportk; 161 | 162 | int joyOct; // Octave shifting by joystick or potentiometer 163 | 164 | //_______________________________________________________________________________________________ SETUP 165 | 166 | void setup() { 167 | 168 | state = NOTE_OFF; // initialize state machine 169 | 170 | pinMode(LedPin,OUTPUT); // declare the LED's pin as output 171 | 172 | // joystick buttons for midi panic 173 | pinMode(11,INPUT_PULLUP); // panic pin 1/2 174 | pinMode(12,INPUT_PULLUP); // panic pin 2/2 175 | 176 | // Set up touch sensor 177 | if (!touchSensor.begin(0x5A)) { 178 | while (1); // Touch sensor initialization failed - stop doing stuff 179 | } 180 | // Set the selection for Casio fingering - Pitch stick up at power on changes from default 181 | if (analogRead(A6) > octsHi_Thr) { 182 | casiomodSelect=!casioMod; 183 | } else{ 184 | casiomodSelect=casioMod; 185 | } 186 | for (x=1; x<=4; x++){ // Do the flashy-flashy to say we are up and running 187 | digitalWrite( LedPin, HIGH ); 188 | delay(300); 189 | digitalWrite( LedPin, LOW ); 190 | delay(300); 191 | } 192 | 193 | Serial.begin(31250); // start serial with midi baudrate 31250 194 | Serial.flush(); 195 | } 196 | 197 | //_______________________________________________________________________________________________ MAIN LOOP 198 | 199 | void loop() { 200 | 201 | // if both joystick buttons are pressed, send all notes off 202 | if ((digitalRead(11) == 0) && (digitalRead(12) == 0)){ 203 | midiPanic(); 204 | } 205 | 206 | pressureSensor = analogRead(A3); // Get the pressure sensor reading from analog pin A3 207 | 208 | if (state == NOTE_OFF) { 209 | if (pressureSensor > ON_Thr) { 210 | // Value has risen above threshold. Move to the ON_Delay 211 | // state. Record time and initial breath value. 212 | breath_on_time = millis(); 213 | initial_breath_value = pressureSensor; 214 | state = RISE_WAIT; // Go to next state 215 | } 216 | } else if (state == RISE_WAIT) { 217 | if (pressureSensor > ON_Thr) { 218 | // Has enough time passed for us to collect our second 219 | // sample? 220 | if (millis() - breath_on_time > ON_Delay) { 221 | // Yes, so calculate MIDI note and velocity, then send a note on event 222 | readSwitches(); 223 | readOctaves(); 224 | oldportk=2; // Set oldportk to a value other than 1 or 0 to make sure it always sends the data for new notes 225 | portamento(); 226 | // We should be at tonguing peak, so set velocity based on current pressureSensor value 227 | // If initial value is greater than value after delay, go with initial value, constrain input to keep mapped output within 7 to 127 228 | velocity = map(constrain(max(pressureSensor,initial_breath_value),ON_Thr,breath_max),ON_Thr,breath_max,7,127); 229 | breathLevel=constrain(max(pressureSensor,initial_breath_value),ON_Thr,breath_max); 230 | breath(); 231 | midiSend((0x90 | MIDIchannel), fingeredNote, velocity); // send Note On message for new note 232 | activeNote=fingeredNote; 233 | state = NOTE_ON; 234 | } 235 | } else { 236 | // Value fell below threshold before ON_Delay passed. Return to 237 | // NOTE_OFF state (e.g. we're ignoring a short blip of breath) 238 | state = NOTE_OFF; 239 | } 240 | } else if (state == NOTE_ON) { 241 | if (pressureSensor < ON_Thr) { 242 | // Value has fallen below threshold - turn the note off 243 | midiSend((0x80 | MIDIchannel), activeNote, velocity); // send Note Off message 244 | breathLevel=0; 245 | state = NOTE_OFF; 246 | } else { 247 | // Is it time to send more CC data? 248 | if (millis() - ccSendTime > CC_INTERVAL) { 249 | // deal with Breath, Pitch Bend and Modulation 250 | breath(); 251 | pitch_bend(); 252 | modulation(); 253 | ccSendTime = millis(); 254 | } 255 | readSwitches(); 256 | readOctaves(); 257 | if (fingeredNote != lastFingering){ // 258 | // reset the debouncing timer 259 | lastDebounceTime = millis(); 260 | } 261 | if ((millis() - lastDebounceTime) > debounceDelay) { 262 | // whatever the reading is at, it's been there for longer 263 | // than the debounce delay, so take it as the actual current state 264 | if (fingeredNote != activeNote) { 265 | // Player has moved to a new fingering while still blowing. 266 | // Send a note off for the current note and a note on for 267 | // the new note. 268 | portamento(); 269 | velocity = map(constrain(pressureSensor,ON_Thr,breath_max),ON_Thr,breath_max,7,127); // set new velocity value based on current pressure sensor level 270 | midiSend((0x90 | MIDIchannel), fingeredNote, velocity); // send Note On message for new note 271 | midiSend((0x80 | MIDIchannel), activeNote, 0); // send Note Off message for previous note (legato) 272 | activeNote=fingeredNote; 273 | } 274 | } 275 | } 276 | } 277 | lastFingering=fingeredNote; 278 | } 279 | //_______________________________________________________________________________________________ FUNCTIONS 280 | 281 | // Send a three byte midi message 282 | void midiSend(byte midistatus, byte data1, byte data2) { 283 | digitalWrite(LedPin,HIGH); // indicate we're sending MIDI data 284 | Serial.write(midistatus); 285 | Serial.write(data1); 286 | Serial.write(data2); 287 | digitalWrite(LedPin,LOW); // indicate we're sending MIDI data 288 | } 289 | 290 | //************************************************************** 291 | 292 | void midiPanic(){ 293 | for (int i = 0; i < 128; i++){ 294 | midiSend((0x80 | MIDIchannel), i, 0); 295 | } 296 | } 297 | 298 | //************************************************************** 299 | 300 | void pitch_bend(){ 301 | int pitchLSB; 302 | int pitchMSB; 303 | pitchBend = analogRead(A0); // read voltage on analog pin A0 304 | if (pitchBend > modsHi_Thr){ 305 | pitchBend = map(pitchBend,modsHi_Thr,1023,8192,(8192 + PB_sens)); // go from 8192 to 16383 (full pb up) when off center threshold going up 306 | } else if (pitchBend < modsLo_Thr){ 307 | pitchBend = map(pitchBend,0,modsLo_Thr,(8191 - PB_sens),8192); // go from 8192 to 0 (full pb dn) when off center threshold going down 308 | } else { 309 | pitchBend = 8192; // 8192 is 0 pitch bend 310 | } 311 | if (pitchBend != oldpb){// only send midi data if pitch bend has changed from previous value 312 | pitchLSB = pitchBend & 0x007F; 313 | pitchMSB = (pitchBend >>7) & 0x007F; 314 | midiSend((0xE0 | MIDIchannel), pitchLSB, pitchMSB); 315 | oldpb=pitchBend; 316 | } 317 | } 318 | 319 | //*********************************************************** 320 | 321 | void modulation(){ 322 | modLevel = analogRead(A1); // read voltage on analog pin A1 323 | if (modLevel > modsHi_Thr){ 324 | modLevel = map(modLevel,modsHi_Thr,1023,0,127); // go from 0 to full modulation when off center threshold going right(?) 325 | } else if (modLevel < modsLo_Thr){ 326 | modLevel = map(modLevel,0,modsLo_Thr,127,0); // go from 0 to full modulation when off center threshold going left(?) 327 | } else { 328 | modLevel = 0; // zero modulation in center position 329 | } 330 | if (modLevel != oldmod){ // only send midi data if modulation has changed from previous value 331 | midiSend((0xB0 | MIDIchannel), 1, modLevel); 332 | oldmod=modLevel; 333 | } 334 | } 335 | 336 | //*********************************************************** 337 | 338 | void portamento(){ 339 | portLevel = map(analogRead(A2),0,1023,0,127); // read voltage on analog pin A7 and map to midi value 340 | if (portLevel != oldport){ // only send midi data if level has changed from previous value 341 | midiSend((0xB0 | MIDIchannel), 5, portLevel); 342 | oldport=portLevel; 343 | } 344 | if (PortK != oldportk){ // only send midi data if status has changed from previous value 345 | if (PortK){ 346 | midiSend((0xB0 | MIDIchannel), 65, 127); // send portamento on 347 | } 348 | else { 349 | midiSend((0xB0 | MIDIchannel), 65, 0); // send portamento off 350 | } 351 | oldportk=PortK; 352 | } 353 | } 354 | 355 | //*********************************************************** 356 | 357 | void breath(){ 358 | int breathCC; 359 | breathLevel = breathLevel*0.8+pressureSensor*0.2; // smoothing of breathLevel value 360 | breathCC = map(constrain(breathLevel,ON_Thr,breath_max),ON_Thr,breath_max,0,127); 361 | midiSend((0xB0 | MIDIchannel), 2, breathCC); 362 | } 363 | //*********************************************************** 364 | 365 | void readOctaves(){ 366 | // Read octave joystick and set octave of the fingered note (run after readSwitches) 367 | int xOctaves; 368 | int yOctaves; 369 | xOctaves = analogRead(A6); // read voltage on analog pin A6 370 | yOctaves = analogRead(A7); // read voltage on analog pin A7 (this is now a separate potentiometer, not joystick axis) 371 | joyOct = 0; 372 | // xOctaves is up/down and the only used octave joystick direction in this version 373 | if (xOctaves > octsHi_Thr) { 374 | joyOct++; 375 | } else if (xOctaves < octsLo_Thr) { 376 | joyOct--; 377 | } 378 | // yOctaves in this version is a separate potentiometer setting base octave -2 to +2 379 | if (yOctaves > octsHi1_Thr) { 380 | joyOct++; // ++ or -- depending on joystick orientation 381 | } else if (yOctaves < octsLo1_Thr) { 382 | joyOct--; // ++ or -- depending on joystick orientation 383 | } 384 | if (yOctaves > octsHi2_Thr) { 385 | joyOct++; // ++ or -- depending on joystick orientation 386 | } else if (yOctaves < octsLo2_Thr) { 387 | joyOct--; // ++ or -- depending on joystick orientation 388 | } 389 | //calculate midi note number from octave shifts 390 | fingeredNote=fingeredNote+joyOct*12; 391 | } 392 | //*********************************************************** 393 | 394 | void readSwitches(){ 395 | // Read switches and put value in variables 396 | uint16_t touchValue = touchSensor.touched(); 397 | LH1=((touchValue >> 0) & 0x01); 398 | LHb=((touchValue >> 1) & 0x01); 399 | LH2=((touchValue >> 2) & 0x01); 400 | LH3=((touchValue >> 3) & 0x01); 401 | LHp1=((touchValue >> 4) & 0x01); 402 | RH1=((touchValue >> 6) & 0x01); 403 | RH2=((touchValue >> 7) & 0x01); 404 | RH3=((touchValue >> 8) & 0x01); 405 | RHp2=((touchValue >> 9) & 0x01); 406 | RHp3=((touchValue >> 10) & 0x01); 407 | PortK=((touchValue >> 5) & 0x01); // portamento key 408 | //calculate midi note number from pressed keys 409 | if (casiomodSelect){ 410 | fingeredNote=startNote-2*LH1-(LHb && !LH2)-LH2-(LH2 && LH1)-2*LH3+LHp1-LHp2+(RHs && !LHp1)-RH1-(RH1 && LH3)-RH2-2*RH3+RHp1-RHp2-2*RHp3+12*OCTup-12*OCTdn+9*(!LH1 && LH2 && LH3); 411 | } else { 412 | fingeredNote=startNote-2*LH1-(LHb && !(LH1 && LH2))-LH2-(LH2 && LH1)-2*LH3+LHp1-LHp2+(RHs && !LHp1)-RH1-(RH1 && LH3)-RH2-2*RH3+RHp1-RHp2-2*RHp3+12*OCTup-12*OCTdn; 413 | } 414 | } 415 | -------------------------------------------------------------------------------- /MiniWI-cap-pmt/MiniWI-fingering-casiomod.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trasselfrisyr/MiniWI/539163e4f242e2ff6e4cc9de6d08df4fdd62859f/MiniWI-cap-pmt/MiniWI-fingering-casiomod.png -------------------------------------------------------------------------------- /MiniWI-cap-pmt/pmtver.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trasselfrisyr/MiniWI/539163e4f242e2ff6e4cc9de6d08df4fdd62859f/MiniWI-cap-pmt/pmtver.png -------------------------------------------------------------------------------- /MiniWI-cap/MiniWI-cap-schematic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trasselfrisyr/MiniWI/539163e4f242e2ff6e4cc9de6d08df4fdd62859f/MiniWI-cap/MiniWI-cap-schematic.png -------------------------------------------------------------------------------- /MiniWI-cap/MiniWI-cap.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /* 5 | NAME: MiniWI Cap Touch ver. 6 | WRITTEN BY: JOHAN BERGLUND 7 | CREDITS: State machine from the Gordophone blog by GORDON GOOD 8 | DATE: 2016-04-13 9 | FILE SAVED AS: MiniWI-cap.ino 10 | FOR: Arduino Pro Mini, ATmega328, version with breakouts for A6 and A7 11 | CLOCK: 16.00 MHz CRYSTAL 12 | PROGRAMME FUNCTION: Wind Controller with EWI style key setup (reduced), Freescale MPX5010GP breath sensor, PS2 style thumb joysticks 13 | for octave selection and pb/mod control, capacitive touch keys, output to 5-pin DIN MIDI 14 | 15 | HARDWARE NOTES: 16 | * For the MIDI connection, attach a MIDI out Female 180 Degree 5-Pin DIN socket to Arduino. 17 | * Socket is seen from solder tags at rear. 18 | * DIN-5 pinout is: _______ 19 | * pin 2 - GND / \ 20 | * pin 4 - 220 ohm resistor to +5V | 1 3 | MIDI jack 21 | * pin 5 - Arduino Pin 1 (TX) via a 220 ohm resistor | 4 5 | 22 | * all other pins - unconnected \___2___/ 23 | * 24 | * Left hand thumb joystick controls octaves. 25 | * X and Y are connected to Arduino pins A6 and A7, 26 | * this means a Pro Mini version with breakouts for these pins is required. 27 | * 28 | * +1 +2 29 | * ^ 30 | * -1 < o > +1 31 | * v 32 | * -2 -1 33 | * 34 | * Right hand thumb joystick controls pitch bend and modulation. 35 | * Pitch bend and modulation are connected to Arduino pins A0 and A1, 36 | * on DIP rows. 37 | * 38 | * PB up 39 | * ^ 40 | * Mod < o > Mod 41 | * v 42 | * PB dn 43 | * 44 | * The Freescale MPX5010GP pressure sensor output (V OUT) is connected to Arduino pin A3. 45 | * 46 | * Sensor pinout 47 | * 1: V OUT (pin with indent) 48 | * 2: GND 49 | * 3: VCC (to 5V) 50 | * 4: n/c 51 | * 5: n/c 52 | * 6: n/c 53 | * 54 | * 55 | * Adafruit MPR121 board connected to Arduino I2C ports (A4-SDA and A5-SCL on the Pro Mini) 56 | * 57 | * Midi panic on pin 11 and 12 (internal pullup, both pins low sends all notes off) 58 | * 59 | */ 60 | 61 | //_______________________________________________________________________________________________ DECLARATIONS 62 | 63 | #define ON_Thr 40 // Set threshold level before switching ON 64 | #define ON_Delay 20 // Set Delay after ON threshold before velocity is checked (wait for tounging peak) 65 | #define breath_max 300 // Blowing as hard as you can 66 | #define modsLo_Thr 411 // Low threshold for mod stick center 67 | #define modsHi_Thr 611 // High threshold for mod stick center 68 | #define octsLo_Thr 311 // Low threshold for octave stick center 69 | #define octsHi_Thr 711 // High threshold for octave stick center 70 | #define PB_sens 4095 // Pitch Bend sensitivity 0 to 8191 where 8191 is full pb range 71 | 72 | // The three states of our state machine 73 | 74 | // No note is sounding 75 | #define NOTE_OFF 1 76 | 77 | // We've observed a transition from below to above the 78 | // threshold value. We wait a while to see how fast the 79 | // breath velocity is increasing 80 | #define RISE_WAIT 2 81 | 82 | // A note is sounding 83 | #define NOTE_ON 3 84 | 85 | // Send CC data no more than every CC_INTERVAL 86 | // milliseconds 87 | #define CC_INTERVAL 15 88 | 89 | 90 | //variables setup 91 | 92 | int state; // The state of the state machine 93 | unsigned long ccSendTime = 0L; // The last time we sent CC values 94 | unsigned long breath_on_time = 0L; // Time when breath sensor value went over the ON threshold 95 | int initial_breath_value; // The breath value at the time we observed the transition 96 | 97 | long lastDebounceTime = 0; // The last time the fingering was changed 98 | long debounceDelay = 30; // The debounce time; increase if the output flickers 99 | int lastFingering = 0; // Keep the last fingering value for debouncing 100 | 101 | byte MIDIchannel=0; // MIDI channel 1 102 | 103 | int modLevel; 104 | int oldmod=0; 105 | 106 | int pitchBend; 107 | int oldpb=8192; 108 | 109 | int breathLevel=0; // breath level (smoothed) not mapped to CC value 110 | 111 | int pressureSensor; // pressure data from breath sensor, for midi breath cc and breath threshold checks 112 | byte velocity; // remapped midi velocity from breath sensor 113 | 114 | int fingeredNote; // note calculated from fingering (switches) and octave joystick position 115 | byte activeNote; // note playing 116 | byte startNote=73; // set startNote to C# (change this value in steps of 12 to start in other octaves) 117 | 118 | byte midistatus=0; 119 | byte x; 120 | byte LedPin = 13; // select the pin for the LED 121 | 122 | Adafruit_MPR121 touchSensor = Adafruit_MPR121(); // This is the 12-input touch sensor 123 | 124 | // Key variables, TRUE (1) for pressed, FALSE (0) for not pressed 125 | byte LH1; // Left Hand key 1 (pitch change -2) 126 | byte LHb; // Left Hand bis key (pitch change -1 unless both LH1 and LH2 are pressed) 127 | byte LH2; // Left Hand key 2 (with LH1 also pressed pitch change is -2, otherwise -1) 128 | byte LH3; // Left Hand key 3 (pitch change -2) 129 | byte LHp1; // Left Hand pinky key 1 (pitch change +1) 130 | byte LHp2=0; // Left Hand pinky key 2 (pitch change -1) --- Not used in this version 131 | byte RHs=0; // Right Hand side key (pitch change -2 unless LHp1 is pressed) --- Not used in this version 132 | byte RH1; // Right Hand key 1 (with LH3 also pressed pitch change is -2, otherwise -1) 133 | byte RH2; // Right Hand key 2 (pitch change -1) 134 | byte RH3; // Right Hand key 3 (pitch change -2) 135 | byte RHp1=0; // Right Hand pinky key 1 (pitch change +1) --- Not used in this version 136 | byte RHp2; // Right Hand pinky key 2 (pitch change -1) 137 | byte RHp3; // Right Hand pinky key 3 (pitch change -2) 138 | byte OCTup=0; // Octave switch key (pitch change +12) --- Not used in this version 139 | byte OCTdn=0; // Octave switch key (pitch change -12) --- Not used in this version 140 | 141 | int joyOct; // Octave shifting by joystick (pitch change steps of 12) value from -2 to +2, 0 is center pos 142 | 143 | //_______________________________________________________________________________________________ SETUP 144 | 145 | void setup() { 146 | 147 | state = NOTE_OFF; // initialize state machine 148 | 149 | pinMode(LedPin,OUTPUT); // declare the LED's pin as output 150 | 151 | // joystick buttons for midi panic 152 | pinMode(11,INPUT_PULLUP); // panic pin 1/2 153 | pinMode(12,INPUT_PULLUP); // panic pin 2/2 154 | 155 | // Set up touch sensor 156 | if (!touchSensor.begin(0x5A)) { 157 | while (1); // Touch sensor initialization failed - stop doing stuff 158 | } 159 | for (x=1; x<=4; x++){ // Do the flashy-flashy to say we are up and running 160 | digitalWrite( LedPin, HIGH ); 161 | delay(300); 162 | digitalWrite( LedPin, LOW ); 163 | delay(300); 164 | } 165 | 166 | Serial.begin(31250); // start serial with midi baudrate 31250 167 | Serial.flush(); 168 | } 169 | 170 | //_______________________________________________________________________________________________ MAIN LOOP 171 | 172 | void loop() { 173 | 174 | // if both joystick buttons are pressed, send all notes off 175 | if ((digitalRead(11) == 0) && (digitalRead(12) == 0)){ 176 | midiPanic(); 177 | } 178 | 179 | pressureSensor = analogRead(A3); // Get the pressure sensor reading from analog pin A3 180 | 181 | if (state == NOTE_OFF) { 182 | if (pressureSensor > ON_Thr) { 183 | // Value has risen above threshold. Move to the ON_Delay 184 | // state. Record time and initial breath value. 185 | breath_on_time = millis(); 186 | initial_breath_value = pressureSensor; 187 | state = RISE_WAIT; // Go to next state 188 | } 189 | } else if (state == RISE_WAIT) { 190 | if (pressureSensor > ON_Thr) { 191 | // Has enough time passed for us to collect our second 192 | // sample? 193 | if (millis() - breath_on_time > ON_Delay) { 194 | // Yes, so calculate MIDI note and velocity, then send a note on event 195 | readSwitches(); 196 | readOctaves(); 197 | // We should be at tonguing peak, so set velocity based on current pressureSensor value 198 | // If initial value is greater than value after delay, go with initial value, constrain input to keep mapped output within 7 to 127 199 | velocity = map(constrain(max(pressureSensor,initial_breath_value),ON_Thr,breath_max),ON_Thr,breath_max,7,127); 200 | breathLevel=constrain(max(pressureSensor,initial_breath_value),ON_Thr,breath_max); 201 | midiSend((0x90 | MIDIchannel), fingeredNote, velocity); // send Note On message for new note 202 | activeNote=fingeredNote; 203 | state = NOTE_ON; 204 | } 205 | } else { 206 | // Value fell below threshold before ON_Delay passed. Return to 207 | // NOTE_OFF state (e.g. we're ignoring a short blip of breath) 208 | state = NOTE_OFF; 209 | } 210 | } else if (state == NOTE_ON) { 211 | if (pressureSensor < ON_Thr) { 212 | // Value has fallen below threshold - turn the note off 213 | midiSend((0x80 | MIDIchannel), activeNote, velocity); // send Note Off message 214 | breathLevel=0; 215 | state = NOTE_OFF; 216 | } else { 217 | // Is it time to send more CC data? 218 | if (millis() - ccSendTime > CC_INTERVAL) { 219 | // deal with Breath, Pitch Bend and Modulation 220 | breath(); 221 | pitch_bend(); 222 | modulation(); 223 | ccSendTime = millis(); 224 | } 225 | readSwitches(); 226 | readOctaves(); 227 | if (fingeredNote != lastFingering){ // 228 | // reset the debouncing timer 229 | lastDebounceTime = millis(); 230 | } 231 | if ((millis() - lastDebounceTime) > debounceDelay) { 232 | // whatever the reading is at, it's been there for longer 233 | // than the debounce delay, so take it as the actual current state 234 | if (fingeredNote != activeNote) { 235 | // Player has moved to a new fingering while still blowing. 236 | // Send a note off for the current note and a note on for 237 | // the new note. 238 | midiSend((0x80 | MIDIchannel), activeNote, velocity); // send Note Off message 239 | activeNote=fingeredNote; 240 | velocity = map(constrain(pressureSensor,ON_Thr,breath_max),ON_Thr,breath_max,7,127); // set new velocity value based on current pressure sensor level 241 | midiSend((0x90 | MIDIchannel), activeNote, velocity); // send Note On message 242 | } 243 | } 244 | } 245 | } 246 | lastFingering=fingeredNote; 247 | } 248 | //_______________________________________________________________________________________________ FUNCTIONS 249 | 250 | // Send a three byte midi message 251 | void midiSend(byte midistatus, byte data1, byte data2) { 252 | digitalWrite(LedPin,HIGH); // indicate we're sending MIDI data 253 | Serial.write(midistatus); 254 | Serial.write(data1); 255 | Serial.write(data2); 256 | digitalWrite(LedPin,LOW); // indicate we're sending MIDI data 257 | } 258 | 259 | //************************************************************** 260 | 261 | void midiPanic(){ 262 | for (int i = 0; i < 128; i++){ 263 | midiSend((0x80 | MIDIchannel), i, 0); 264 | } 265 | } 266 | 267 | //************************************************************** 268 | 269 | void pitch_bend(){ 270 | int pitchLSB; 271 | int pitchMSB; 272 | pitchBend = analogRead(A0); // read voltage on analog pin A0 273 | if (pitchBend > modsHi_Thr){ 274 | pitchBend = map(pitchBend,modsHi_Thr,1023,8192,(8192 + PB_sens)); // go from 8192 to 16383 (full pb up) when off center threshold going up 275 | } else if (pitchBend < modsLo_Thr){ 276 | pitchBend = map(pitchBend,0,modsLo_Thr,(8191 - PB_sens),8192); // go from 8192 to 0 (full pb dn) when off center threshold going down 277 | } else { 278 | pitchBend = 8192; // 8192 is 0 pitch bend 279 | } 280 | if (pitchBend != oldpb){// only send midi data if pitch bend has changed from previous value 281 | pitchLSB = pitchBend & 0x007F; 282 | pitchMSB = (pitchBend >>7) & 0x007F; 283 | midiSend((0xE0 | MIDIchannel), pitchLSB, pitchMSB); 284 | oldpb=pitchBend; 285 | } 286 | } 287 | 288 | //*********************************************************** 289 | 290 | void modulation(){ 291 | modLevel = analogRead(A1); // read voltage on analog pin A1 292 | if (modLevel > modsHi_Thr){ 293 | modLevel = map(modLevel,modsHi_Thr,1023,0,127); // go from 0 to full modulation when off center threshold going right(?) 294 | } else if (modLevel < modsLo_Thr){ 295 | modLevel = map(modLevel,0,modsLo_Thr,127,0); // go from 0 to full modulation when off center threshold going left(?) 296 | } else { 297 | modLevel = 0; // zero modulation in center position 298 | } 299 | if (modLevel != oldmod){ // only send midi data if modulation has changed from previous value 300 | midiSend((0xB0 | MIDIchannel), 1, modLevel); 301 | oldmod=modLevel; 302 | } 303 | } 304 | 305 | //*********************************************************** 306 | 307 | void breath(){ 308 | int breathCC; 309 | breathLevel = breathLevel*0.8+pressureSensor*0.2; // smoothing of breathLevel value 310 | breathCC = map(constrain(breathLevel,ON_Thr,breath_max),ON_Thr,breath_max,0,127); 311 | midiSend((0xB0 | MIDIchannel), 2, breathCC); 312 | } 313 | //*********************************************************** 314 | 315 | void readOctaves(){ 316 | // Read octave joystick directions combining x and y to a span of 5 octaves (-2 to +2) where 0 is center position 317 | int xOctaves; 318 | int yOctaves; 319 | xOctaves = analogRead(A6); // read voltage on analog pin A6 320 | yOctaves = analogRead(A7); // read voltage on analog pin A7 321 | joyOct = 0; 322 | if (xOctaves > octsHi_Thr) { 323 | joyOct++; // ++ or -- depending on joystick orientation 324 | } else if (xOctaves < octsLo_Thr) { 325 | joyOct--; // ++ or -- depending on joystick orientation 326 | } 327 | 328 | if (yOctaves > octsHi_Thr) { 329 | joyOct++; // ++ or -- depending on joystick orientation 330 | } else if (yOctaves < octsLo_Thr) { 331 | joyOct--; // ++ or -- depending on joystick orientation 332 | } 333 | //calculate midi note number from octave shifts 334 | fingeredNote=fingeredNote+joyOct*12; 335 | } 336 | //*********************************************************** 337 | 338 | void readSwitches(){ 339 | // Read switches and put value in variables 340 | uint16_t touchValue = touchSensor.touched(); 341 | LH1=((touchValue >> 0) & 0x01); 342 | LHb=((touchValue >> 1) & 0x01); 343 | LH2=((touchValue >> 2) & 0x01); 344 | LH3=((touchValue >> 3) & 0x01); 345 | LHp1=((touchValue >> 4) & 0x01); 346 | RH1=((touchValue >> 6) & 0x01); 347 | RH2=((touchValue >> 7) & 0x01); 348 | RH3=((touchValue >> 8) & 0x01); 349 | RHp2=((touchValue >> 9) & 0x01); 350 | RHp3=((touchValue >> 10) & 0x01); 351 | //calculate midi note number from pressed keys 352 | fingeredNote=startNote-2*LH1-(LHb && !(LH1 && LH2))-LH2-(LH2 && LH1)-2*LH3+LHp1-LHp2+(RHs && !LHp1)-RH1-(RH1 && LH3)-RH2-2*RH3+RHp1-RHp2-2*RHp3+12*OCTup-12*OCTdn; 353 | } 354 | -------------------------------------------------------------------------------- /MiniWI-cap/capverbottom.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trasselfrisyr/MiniWI/539163e4f242e2ff6e4cc9de6d08df4fdd62859f/MiniWI-cap/capverbottom.png -------------------------------------------------------------------------------- /MiniWI-cap/capverinside.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trasselfrisyr/MiniWI/539163e4f242e2ff6e4cc9de6d08df4fdd62859f/MiniWI-cap/capverinside.png -------------------------------------------------------------------------------- /MiniWI-cap/capvertop.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trasselfrisyr/MiniWI/539163e4f242e2ff6e4cc9de6d08df4fdd62859f/MiniWI-cap/capvertop.png -------------------------------------------------------------------------------- /MiniWI-lite/MiniWI-lite.ino: -------------------------------------------------------------------------------- 1 | /* 2 | NAME: MiniWI Lite Ver. 3 | WRITTEN BY: JOHAN BERGLUND 4 | CREDITS: State machine from the Gordophone blog by GORDON GOOD 5 | DATE: 2016-04-13 6 | FILE SAVED AS: MiniWI-lite.ino 7 | FOR: Arduino Pro Mini, ATmega328 8 | CLOCK: 16.00 MHz CRYSTAL 9 | PROGRAMME FUNCTION: Wind Controller with EWI style key setup, Freescale MPX5010GP breath sensor 10 | and output to 5-pin DIN MIDI 11 | 12 | HARDWARE NOTES: 13 | * For the MIDI connection, attach a MIDI out Female 180 Degree 5-Pin DIN socket to Arduino. 14 | * Socket is seen from solder tags at rear. 15 | * DIN-5 pinout is: _______ 16 | * pin 2 - GND / \ 17 | * pin 4 - 220 ohm resistor to +5V | 1 3 | MIDI jack 18 | * pin 5 - Arduino Pin 1 (TX) via a 220 ohm resistor | 4 5 | 19 | * all other pins - unconnected \___2___/ 20 | * 21 | * The Freescale MPX5010GP pressure sensor output (V OUT) is connected to Arduino pin A3. 22 | * 23 | * Sensor pinout 24 | * 1: V OUT (pin with indent) 25 | * 2: GND 26 | * 3: VCC (to 5V) 27 | * 4: n/c 28 | * 5: n/c 29 | * 6: n/c 30 | * 31 | * 32 | * All key switches connect Ardino digital inputs (with internal pullups) to GND 33 | * 34 | */ 35 | 36 | //_______________________________________________________________________________________________ DECLARATIONS 37 | 38 | #define ON_Thr 40 // Set threshold level before switching ON 39 | #define ON_Delay 20 // Set Delay after ON threshold before velocity is checked (wait for tounging peak) 40 | #define breath_max 300 // Blowing as hard as you can 41 | #define modsLo_Thr 411 // Low threshold for mod stick center 42 | #define modsHi_Thr 611 // High threshold for mod stick center 43 | #define octsLo_Thr 311 // Low threshold for octave stick center 44 | #define octsHi_Thr 711 // High threshold for octave stick center 45 | 46 | // The three states of our state machine 47 | 48 | // No note is sounding 49 | #define NOTE_OFF 1 50 | 51 | // We've observed a transition from below to above the 52 | // threshold value. We wait a while to see how fast the 53 | // breath velocity is increasing 54 | #define RISE_WAIT 2 55 | 56 | // A note is sounding 57 | #define NOTE_ON 3 58 | 59 | // Send CC data no more than every CC_INTERVAL 60 | // milliseconds 61 | #define CC_INTERVAL 40 62 | 63 | 64 | //variables setup 65 | 66 | int state; // The state of the state machine 67 | unsigned long ccSendTime = 0L; // The last time we sent CC values 68 | unsigned long breath_on_time = 0L; // Time when breath sensor value went over the ON threshold 69 | int initial_breath_value; // The breath value at the time we observed the transition 70 | 71 | long lastDebounceTime = 0; // The last time the fingering was changed 72 | long debounceDelay = 30; // The debounce time; increase if the output flickers 73 | int lastFingering = 0; // Keep the last fingering value for debouncing 74 | 75 | byte MIDIchannel=0; // MIDI channel 1 76 | 77 | int breathLevel; 78 | 79 | int pressureSensor; // pressure data from breath sensor, for midi breath cc and breath threshold checks 80 | byte velocity; // remapped midi velocity from breath sensor 81 | 82 | int fingeredNote; // note calculated from fingering (switches) and octave joystick position 83 | byte activeNote; // note playing 84 | byte startNote=61; // set startNote to C# (change this value in steps of 12 to start in other octaves) 85 | 86 | byte midistatus=0; 87 | byte x; 88 | byte LedPin = 13; // select the pin for the LED 89 | 90 | // Key variables, TRUE (1) for pressed, FALSE (0) for not pressed 91 | byte LH1; // Left Hand key 1 (pitch change -2) 92 | byte LHb; // Left Hand bis key (pitch change -1 unless both LH1 and LH2 are pressed) 93 | byte LH2; // Left Hand key 2 (with LH1 also pressed pitch change is -2, otherwise -1) 94 | byte LH3; // Left Hand key 3 (pitch change -2) 95 | byte LHp1; // Left Hand pinky key 1 (pitch change +1) 96 | byte LHp2; // Left Hand pinky key 2 (pitch change -1) 97 | byte RHs; // Right Hand side key (pitch change -2 unless LHp1 is pressed) 98 | byte RH1; // Right Hand key 1 (with LH3 also pressed pitch change is -2, otherwise -1) 99 | byte RH2; // Right Hand key 2 (pitch change -1) 100 | byte RH3; // Right Hand key 3 (pitch change -2) 101 | byte RHp1; // Right Hand pinky key 1 (pitch change +1) 102 | byte RHp2; // Right Hand pinky key 2 (pitch change -1) 103 | byte RHp3; // Right Hand pinky key 3 (pitch change -2) 104 | byte OCTup; // Octave switch key (pitch change +12) 105 | 106 | 107 | 108 | //_______________________________________________________________________________________________ SETUP 109 | 110 | void setup() { 111 | pinMode(2, INPUT_PULLUP); // Set inputs with pull-up 112 | pinMode(3, INPUT_PULLUP); 113 | pinMode(4, INPUT_PULLUP); 114 | pinMode(5, INPUT_PULLUP); 115 | pinMode(6, INPUT_PULLUP); 116 | pinMode(7, INPUT_PULLUP); 117 | pinMode(8, INPUT_PULLUP); 118 | pinMode(9, INPUT_PULLUP); 119 | pinMode(10, INPUT_PULLUP); 120 | pinMode(11, INPUT_PULLUP); 121 | pinMode(12, INPUT_PULLUP); 122 | pinMode(14, INPUT_PULLUP); 123 | pinMode(15, INPUT_PULLUP); 124 | pinMode(16, INPUT_PULLUP); 125 | 126 | state = NOTE_OFF; // initialize state machine 127 | 128 | pinMode(LedPin,OUTPUT); // declare the LED's pin as output 129 | 130 | for (x=1; x<=4; x++){ // Do the flashy-flashy to say we are up and running 131 | digitalWrite( LedPin, HIGH ); 132 | delay(300); 133 | digitalWrite( LedPin, LOW ); 134 | delay(300); 135 | } 136 | 137 | Serial.begin(31250); // start serial with midi baudrate 31250 138 | Serial.flush(); 139 | } 140 | 141 | //_______________________________________________________________________________________________ MAIN LOOP 142 | 143 | void loop() { 144 | 145 | pressureSensor = analogRead(A3); // Get the pressure sensor reading from analog pin A3 146 | 147 | if (state == NOTE_OFF) { 148 | if (pressureSensor > ON_Thr) { 149 | // Value has risen above threshold. Move to the ON_Delay 150 | // state. Record time and initial breath value. 151 | breath_on_time = millis(); 152 | initial_breath_value = pressureSensor; 153 | state = RISE_WAIT; // Go to next state 154 | } 155 | } else if (state == RISE_WAIT) { 156 | if (pressureSensor > ON_Thr) { 157 | // Has enough time passed for us to collect our second 158 | // sample? 159 | if (millis() - breath_on_time > ON_Delay) { 160 | // Yes, so calculate MIDI note and velocity, then send a note on event 161 | readSwitches(); 162 | 163 | //calculate midi note number from pressed keys and octave shifts 164 | fingeredNote=startNote-2*LH1-(LHb && !(LH1 && LH2))-LH2-(LH2 && LH1)-2*LH3+LHp1-LHp2+(RHs && !LHp1)-RH1-(RH1 && LH3)-RH2-2*RH3+RHp1-RHp2-2*RHp3+12*OCTup; 165 | 166 | // We should be at tonguing peak, so set velocity based on current pressureSensor value 167 | // If initial value is greater than value after delay, go with initial value, constrain input to keep mapped output within 7 to 127 168 | velocity = map(constrain(max(pressureSensor,initial_breath_value),ON_Thr,breath_max),ON_Thr,breath_max,7,127); 169 | midiSend((0x90 | MIDIchannel), fingeredNote, velocity); // send Note On message for new note 170 | activeNote=fingeredNote; 171 | state = NOTE_ON; 172 | } 173 | } else { 174 | // Value fell below threshold before ON_Delay passed. Return to 175 | // NOTE_OFF state (e.g. we're ignoring a short blip of breath) 176 | state = NOTE_OFF; 177 | } 178 | } else if (state == NOTE_ON) { 179 | if (pressureSensor < ON_Thr) { 180 | // Value has fallen below threshold - turn the note off 181 | midiSend((0x80 | MIDIchannel), activeNote, velocity); // send Note Off message 182 | state = NOTE_OFF; 183 | } else { 184 | // Is it time to send more CC data? 185 | if (millis() - ccSendTime > CC_INTERVAL) { 186 | // deal with Breath 187 | breath(); 188 | ccSendTime = millis(); 189 | } 190 | readSwitches(); 191 | //calculate midi note number from pressed keys 192 | fingeredNote=startNote-2*LH1-(LHb && !(LH1 && LH2))-LH2-(LH2 && LH1)-2*LH3+LHp1-LHp2+(RHs && !LHp1)-RH1-(RH1 && LH3)-RH2-2*RH3+RHp1-RHp2-2*RHp3+12*OCTup; 193 | 194 | if (fingeredNote != lastFingering){ // 195 | // reset the debouncing timer 196 | lastDebounceTime = millis(); 197 | } 198 | if ((millis() - lastDebounceTime) > debounceDelay) { 199 | // whatever the reading is at, it's been there for longer 200 | // than the debounce delay, so take it as the actual current state 201 | if (fingeredNote != activeNote) { 202 | // Player has moved to a new fingering while still blowing. 203 | // Send a note off for the current note and a note on for 204 | // the new note. 205 | midiSend((0x80 | MIDIchannel), activeNote, velocity); // send Note Off message 206 | activeNote=fingeredNote; 207 | velocity = map(constrain(pressureSensor,ON_Thr,breath_max),ON_Thr,breath_max,7,127); // set new velocity value based on current pressure sensor level 208 | midiSend((0x90 | MIDIchannel), activeNote, velocity); // send Note On message 209 | } 210 | } 211 | } 212 | } 213 | lastFingering=fingeredNote; 214 | } 215 | //_______________________________________________________________________________________________ FUNCTIONS 216 | 217 | // Send a three byte midi message 218 | void midiSend(byte midistatus, byte data1, byte data2) { 219 | digitalWrite(LedPin,HIGH); // indicate we're sending MIDI data 220 | Serial.write(midistatus); 221 | Serial.write(data1); 222 | Serial.write(data2); 223 | digitalWrite(LedPin,LOW); // indicate we're sending MIDI data 224 | } 225 | 226 | //*********************************************************** 227 | 228 | void breath(){ 229 | breathLevel = analogRead(A3); // read voltage on analog pin A3 230 | breathLevel = map(constrain(breathLevel,ON_Thr,breath_max),ON_Thr,breath_max,0,127); 231 | midiSend((0xB0 | MIDIchannel), 2, breathLevel); 232 | } 233 | 234 | //*********************************************************** 235 | 236 | void readSwitches(){ 237 | // Read switches and put inverted value in variables 238 | LH1=!digitalRead(2); 239 | LHb=!digitalRead(3); 240 | LH2=!digitalRead(4); 241 | LH3=!digitalRead(5); 242 | LHp1=!digitalRead(6); 243 | LHp2=!digitalRead(7); 244 | RHs=!digitalRead(8); 245 | RH1=!digitalRead(9); 246 | RH2=!digitalRead(10); 247 | RH3=!digitalRead(11); 248 | RHp1=!digitalRead(12); 249 | RHp2=!digitalRead(14); 250 | RHp3=!digitalRead(15); 251 | OCTup=!digitalRead(16); 252 | } 253 | 254 | -------------------------------------------------------------------------------- /MiniWI/MiniWI-schematic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trasselfrisyr/MiniWI/539163e4f242e2ff6e4cc9de6d08df4fdd62859f/MiniWI/MiniWI-schematic.png -------------------------------------------------------------------------------- /MiniWI/MiniWI.ino: -------------------------------------------------------------------------------- 1 | /* 2 | NAME: MiniWI 3 | WRITTEN BY: JOHAN BERGLUND 4 | CREDITS: State machine from the Gordophone blog by GORDON GOOD 5 | DATE: 2016-04-13 6 | FILE SAVED AS: MiniWI.ino 7 | FOR: Arduino Pro Mini, ATmega328, version with breakouts for A6 and A7 8 | CLOCK: 16.00 MHz CRYSTAL 9 | PROGRAMME FUNCTION: Wind Controller with EWI style key setup, Freescale MPX5010GP breath sensor, PS2 style thumb joysticks 10 | for octave selection and pb/mod control, output to 5-pin DIN MIDI 11 | 12 | HARDWARE NOTES: 13 | * For the MIDI connection, attach a MIDI out Female 180 Degree 5-Pin DIN socket to Arduino. 14 | * Socket is seen from solder tags at rear. 15 | * DIN-5 pinout is: _______ 16 | * pin 2 - GND / \ 17 | * pin 4 - 220 ohm resistor to +5V | 1 3 | MIDI jack 18 | * pin 5 - Arduino Pin 1 (TX) via a 220 ohm resistor | 4 5 | 19 | * all other pins - unconnected \___2___/ 20 | * 21 | * Left hand thumb joystick controls octaves. 22 | * X and Y are connected to Arduino pins A6 and A7, 23 | * this means a Pro Mini version with breakouts for these pins is required. 24 | * 25 | * +1 +2 26 | * ^ 27 | * -1 < o > +1 28 | * v 29 | * -2 -1 30 | * 31 | * Right hand thumb joystick controls pitch bend and modulation. 32 | * Pitch bend and modulation are connected to Arduino pins A4 and A5, 33 | * not on DIP rows. 34 | * 35 | * PB up 36 | * ^ 37 | * Mod < o > Mod 38 | * v 39 | * PB dn 40 | * 41 | * The Freescale MPX5010GP pressure sensor output (V OUT) is connected to Arduino pin A3. 42 | * 43 | * Sensor pinout 44 | * 1: V OUT (pin with indent) 45 | * 2: GND 46 | * 3: VCC (to 5V) 47 | * 4: n/c 48 | * 5: n/c 49 | * 6: n/c 50 | * 51 | * 52 | * All key switches connect Arduino digital inputs (with internal pullups) to GND 53 | * 54 | */ 55 | 56 | //_______________________________________________________________________________________________ DECLARATIONS 57 | 58 | #define ON_Thr 40 // Set threshold level before switching ON 59 | #define ON_Delay 20 // Set Delay after ON threshold before velocity is checked (wait for tounging peak) 60 | #define breath_max 300 // Blowing as hard as you can 61 | #define modsLo_Thr 411 // Low threshold for mod stick center 62 | #define modsHi_Thr 611 // High threshold for mod stick center 63 | #define octsLo_Thr 311 // Low threshold for octave stick center 64 | #define octsHi_Thr 711 // High threshold for octave stick center 65 | 66 | // The three states of our state machine 67 | 68 | // No note is sounding 69 | #define NOTE_OFF 1 70 | 71 | // We've observed a transition from below to above the 72 | // threshold value. We wait a while to see how fast the 73 | // breath velocity is increasing 74 | #define RISE_WAIT 2 75 | 76 | // A note is sounding 77 | #define NOTE_ON 3 78 | 79 | // Send CC data no more than every CC_INTERVAL 80 | // milliseconds 81 | #define CC_INTERVAL 15 82 | 83 | 84 | //variables setup 85 | 86 | int state; // The state of the state machine 87 | unsigned long ccSendTime = 0L; // The last time we sent CC values 88 | unsigned long breath_on_time = 0L; // Time when breath sensor value went over the ON threshold 89 | int initial_breath_value; // The breath value at the time we observed the transition 90 | 91 | long lastDebounceTime = 0; // The last time the fingering was changed 92 | long debounceDelay = 30; // The debounce time; increase if the output flickers 93 | int lastFingering = 0; // Keep the last fingering value for debouncing 94 | 95 | byte MIDIchannel=0; // MIDI channel 1 96 | 97 | int modLevel; 98 | int oldmod=0; 99 | 100 | int pitchLSB; 101 | int pitchMSB; 102 | int pitchBend; 103 | int oldpb=8192; 104 | 105 | int breathLevel; 106 | int oldBreath=0; 107 | 108 | int xOctaves; 109 | int yOctaves; 110 | 111 | int pressureSensor; // pressure data from breath sensor, for midi breath cc and breath threshold checks 112 | byte velocity; // remapped midi velocity from breath sensor 113 | 114 | int fingeredNote; // note calculated from fingering (switches) and octave joystick position 115 | byte activeNote; // note playing 116 | byte startNote=61; // set startNote to C# (change this value in steps of 12 to start in other octaves) 117 | 118 | byte midistatus=0; 119 | byte x; 120 | byte LedPin = 13; // select the pin for the LED 121 | 122 | // Key variables, TRUE (1) for pressed, FALSE (0) for not pressed 123 | byte LH1; // Left Hand key 1 (pitch change -2) 124 | byte LHb; // Left Hand bis key (pitch change -1 unless both LH1 and LH2 are pressed) 125 | byte LH2; // Left Hand key 2 (with LH1 also pressed pitch change is -2, otherwise -1) 126 | byte LH3; // Left Hand key 3 (pitch change -2) 127 | byte LHp1; // Left Hand pinky key 1 (pitch change +1) 128 | byte LHp2; // Left Hand pinky key 2 (pitch change -1) 129 | byte RHs; // Right Hand side key (pitch change -2 unless LHp1 is pressed) 130 | byte RH1; // Right Hand key 1 (with LH3 also pressed pitch change is -2, otherwise -1) 131 | byte RH2; // Right Hand key 2 (pitch change -1) 132 | byte RH3; // Right Hand key 3 (pitch change -2) 133 | byte RHp1; // Right Hand pinky key 1 (pitch change +1) 134 | byte RHp2; // Right Hand pinky key 2 (pitch change -1) 135 | byte RHp3; // Right Hand pinky key 3 (pitch change -2) 136 | byte OCTup; // Octave switch key (pitch change +12) // Keep this? Octave joystick button? 137 | 138 | int joyOct; // Octave shifting by joystick (pitch change steps of 12) value from -2 to +2, 0 is center pos 139 | 140 | //_______________________________________________________________________________________________ SETUP 141 | 142 | void setup() { 143 | pinMode(2, INPUT_PULLUP); // Set inputs with pull-up 144 | pinMode(3, INPUT_PULLUP); 145 | pinMode(4, INPUT_PULLUP); 146 | pinMode(5, INPUT_PULLUP); 147 | pinMode(6, INPUT_PULLUP); 148 | pinMode(7, INPUT_PULLUP); 149 | pinMode(8, INPUT_PULLUP); 150 | pinMode(9, INPUT_PULLUP); 151 | pinMode(10, INPUT_PULLUP); 152 | pinMode(11, INPUT_PULLUP); 153 | pinMode(12, INPUT_PULLUP); 154 | pinMode(14, INPUT_PULLUP); 155 | pinMode(15, INPUT_PULLUP); 156 | pinMode(16, INPUT_PULLUP); 157 | 158 | state = NOTE_OFF; // initialize state machine 159 | 160 | pinMode(LedPin,OUTPUT); // declare the LED's pin as output 161 | 162 | for (x=1; x<=4; x++){ // Do the flashy-flashy to say we are up and running 163 | digitalWrite( LedPin, HIGH ); 164 | delay(300); 165 | digitalWrite( LedPin, LOW ); 166 | delay(300); 167 | } 168 | 169 | Serial.begin(31250); // start serial with midi baudrate 31250 170 | Serial.flush(); 171 | } 172 | 173 | //_______________________________________________________________________________________________ MAIN LOOP 174 | 175 | void loop() { 176 | 177 | pressureSensor = analogRead(A3); // Get the pressure sensor reading from analog pin A3 178 | 179 | if (state == NOTE_OFF) { 180 | if (pressureSensor > ON_Thr) { 181 | // Value has risen above threshold. Move to the ON_Delay 182 | // state. Record time and initial breath value. 183 | breath_on_time = millis(); 184 | initial_breath_value = pressureSensor; 185 | state = RISE_WAIT; // Go to next state 186 | } 187 | } else if (state == RISE_WAIT) { 188 | if (pressureSensor > ON_Thr) { 189 | // Has enough time passed for us to collect our second 190 | // sample? 191 | if (millis() - breath_on_time > ON_Delay) { 192 | // Yes, so calculate MIDI note and velocity, then send a note on event 193 | readSwitches(); 194 | readOctaves(); 195 | 196 | //calculate midi note number from pressed keys and octave shifts 197 | fingeredNote=startNote-2*LH1-(LHb && !(LH1 && LH2))-LH2-(LH2 && LH1)-2*LH3+LHp1-LHp2+(RHs && !LHp1)-RH1-(RH1 && LH3)-RH2-2*RH3+RHp1-RHp2-2*RHp3+12*OCTup; 198 | fingeredNote=fingeredNote+joyOct*12; 199 | 200 | // We should be at tonguing peak, so set velocity based on current pressureSensor value 201 | // If initial value is greater than value after delay, go with initial value, constrain input to keep mapped output within 7 to 127 202 | velocity = map(constrain(max(pressureSensor,initial_breath_value),ON_Thr,breath_max),ON_Thr,breath_max,7,127); 203 | midiSend((0x90 | MIDIchannel), fingeredNote, velocity); // send Note On message for new note 204 | activeNote=fingeredNote; 205 | state = NOTE_ON; 206 | } 207 | } else { 208 | // Value fell below threshold before ON_Delay passed. Return to 209 | // NOTE_OFF state (e.g. we're ignoring a short blip of breath) 210 | state = NOTE_OFF; 211 | } 212 | } else if (state == NOTE_ON) { 213 | if (pressureSensor < ON_Thr) { 214 | // Value has fallen below threshold - turn the note off 215 | midiSend((0x80 | MIDIchannel), activeNote, velocity); // send Note Off message 216 | oldBreath=0; 217 | state = NOTE_OFF; 218 | } else { 219 | // Is it time to send more CC data? 220 | if (millis() - ccSendTime > CC_INTERVAL) { 221 | // deal with Breath, Pitch Bend and Modulation 222 | breath(); 223 | pitch_bend(); 224 | modulation(); 225 | ccSendTime = millis(); 226 | } 227 | readSwitches(); 228 | readOctaves(); 229 | 230 | //calculate midi note number from pressed keys and octave shifts 231 | fingeredNote=startNote-2*LH1-(LHb && !(LH1 && LH2))-LH2-(LH2 && LH1)-2*LH3+LHp1-LHp2+(RHs && !LHp1)-RH1-(RH1 && LH3)-RH2-2*RH3+RHp1-RHp2-2*RHp3+12*OCTup; 232 | fingeredNote=fingeredNote+joyOct*12; 233 | 234 | if (fingeredNote != lastFingering){ // 235 | // reset the debouncing timer 236 | lastDebounceTime = millis(); 237 | } 238 | if ((millis() - lastDebounceTime) > debounceDelay) { 239 | // whatever the reading is at, it's been there for longer 240 | // than the debounce delay, so take it as the actual current state 241 | if (fingeredNote != activeNote) { 242 | // Player has moved to a new fingering while still blowing. 243 | // Send a note off for the current note and a note on for 244 | // the new note. 245 | midiSend((0x80 | MIDIchannel), activeNote, velocity); // send Note Off message 246 | activeNote=fingeredNote; 247 | velocity = map(constrain(pressureSensor,ON_Thr,breath_max),ON_Thr,breath_max,7,127); // set new velocity value based on current pressure sensor level 248 | midiSend((0x90 | MIDIchannel), activeNote, velocity); // send Note On message 249 | } 250 | } 251 | } 252 | } 253 | lastFingering=fingeredNote; 254 | } 255 | //_______________________________________________________________________________________________ FUNCTIONS 256 | 257 | // Send a three byte midi message 258 | void midiSend(byte midistatus, byte data1, byte data2) { 259 | digitalWrite(LedPin,HIGH); // indicate we're sending MIDI data 260 | Serial.write(midistatus); 261 | Serial.write(data1); 262 | Serial.write(data2); 263 | digitalWrite(LedPin,LOW); // indicate we're sending MIDI data 264 | } 265 | 266 | //************************************************************** 267 | 268 | void pitch_bend(){ 269 | pitchBend = analogRead(A4); // read voltage on analog pin A4 270 | if (pitchBend > modsHi_Thr){ 271 | pitchBend = map(pitchBend,modsHi_Thr,1023,8192,16383); // go from 8192 to 16383 (full pb up) when off center threshold going up 272 | } else if (pitchBend < modsLo_Thr){ 273 | pitchBend = map(pitchBend,0,modsLo_Thr,0,8192); // go from 8192 to 0 (full pb dn) when off center threshold going down 274 | } else { 275 | pitchBend = 8192; // 8192 is 0 pitch bend 276 | } 277 | if (pitchBend != oldpb){// only send midi data if pitch bend has changed from previous value 278 | pitchLSB = pitchBend & 0x007F; 279 | pitchMSB = (pitchBend >>7) & 0x007F; 280 | midiSend((0xE0 | MIDIchannel), pitchLSB, pitchMSB); 281 | oldpb=pitchBend; 282 | } 283 | } 284 | 285 | //*********************************************************** 286 | 287 | void modulation(){ 288 | modLevel = analogRead(A5); // read voltage on analog pin A5 289 | if (modLevel > modsHi_Thr){ 290 | modLevel = map(modLevel,modsHi_Thr,1023,0,127); // go from 0 to full modulation when off center threshold going right(?) 291 | } else if (modLevel < modsLo_Thr){ 292 | modLevel = map(modLevel,0,modsLo_Thr,127,0); // go from 0 to full modulation when off center threshold going left(?) 293 | } else { 294 | modLevel = 0; // zero modulation in center position 295 | } 296 | if (modLevel != oldmod){ // only send midi data if modulation has changed from previous value 297 | midiSend((0xB0 | MIDIchannel), 1, modLevel); 298 | oldmod=modLevel; 299 | } 300 | } 301 | 302 | //*********************************************************** 303 | 304 | void breath(){ 305 | breathLevel = analogRead(A3); // read voltage on analog pin A3 306 | breathLevel = oldBreath*0.8+breathLevel*0.2; 307 | oldBreath = breathLevel; 308 | breathLevel = map(constrain(breathLevel,ON_Thr,breath_max),ON_Thr,breath_max,0,127); 309 | midiSend((0xB0 | MIDIchannel), 2, breathLevel); 310 | } 311 | //*********************************************************** 312 | 313 | void readOctaves(){ 314 | // Read octave joystick directions combining x and y to a span of 5 octaves (-2 to +2) where 0 is center position 315 | xOctaves = analogRead(A6); // read voltage on analog pin A6 316 | yOctaves = analogRead(A7); // read voltage on analog pin A7 317 | joyOct = 0; 318 | if (xOctaves > octsHi_Thr) { 319 | joyOct++; // ++ or -- depending on joystick orientation 320 | } else if (xOctaves < octsLo_Thr) { 321 | joyOct--; // ++ or -- depending on joystick orientation 322 | } 323 | 324 | if (yOctaves > octsHi_Thr) { 325 | joyOct++; // ++ or -- depending on joystick orientation 326 | } else if (yOctaves < octsLo_Thr) { 327 | joyOct--; // ++ or -- depending on joystick orientation 328 | } 329 | } 330 | //*********************************************************** 331 | 332 | void readSwitches(){ 333 | // Read switches and put inverted value in variables 334 | LH1=!digitalRead(2); 335 | LHb=!digitalRead(3); 336 | LH2=!digitalRead(4); 337 | LH3=!digitalRead(5); 338 | LHp1=!digitalRead(6); 339 | LHp2=!digitalRead(7); 340 | RHs=!digitalRead(8); 341 | RH1=!digitalRead(9); 342 | RH2=!digitalRead(10); 343 | RH3=!digitalRead(11); 344 | RHp1=!digitalRead(12); 345 | RHp2=!digitalRead(14); 346 | RHp3=!digitalRead(15); 347 | OCTup=!digitalRead(16); 348 | } 349 | -------------------------------------------------------------------------------- /MiniWI/miniwifirstproto.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trasselfrisyr/MiniWI/539163e4f242e2ff6e4cc9de6d08df4fdd62859f/MiniWI/miniwifirstproto.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MiniWI 2 | MIDI woodwind controller 3 | 4 | 2016-04-17 5 | 6 | This MIDI controller is running on an Arduino Pro Mini with Atmega328 16MHz/5V. It makes use of breakouts for analog pins A6 and A7, so it needs a Pro Mini version with these breakouts. The pressure sensor used for the project is the Freescale MPX5010GP. Fingering is reverse engineered from Akai EWI and note values are calculated from pressed keys. For details on this, read my guest post on the Gordophone blog. 7 | 8 | http://gordophone.blogspot.se/2016/04/guest-post-alternative-way-of-note.html 9 | 10 | Details on the state machine approach for handling the events is also available on Gordon's blog where I borrowed it from. He's got a step-by-step how-to on DIY wind controllers that I highly recommend. 11 | 12 | http://gordophone.blogspot.se/2013/01/a-series-basics-of-diy-wind-controllers.html 13 | 14 | Hardware notes for connection of MIDI, pressure sensor, keys and joysticks are available in the MiniWI.ino file. 15 | 16 | The MIDI routines and the MIDI connections are pretty standard, but I first found them on the midikits.net website, so I'll give Tom Scarff a mention here. Kept his nice MIDI pinout ASCII sketch thing and some comment style too. 17 | 18 | The controller is made to work well with synthesizers using wind controller patches from Patchman Music, with the breath data sent by CC #2 (Breath). For testing I’ve been using their wind controller soundbank for Roland JV-1010. 19 | 20 | http://www.patchmanmusic.com 21 | 22 | Or you can make your own patches optimized for breath control. Pointers for doing that can also be found on the Patchman website. 23 | 24 | 25 | Questions and suggestions are welcome. Just send them to johan@helgo.net. 26 | 27 | -Johan Berglund 28 | 29 | 30 | 2016-05-17 31 | 32 | Variations: 33 | 34 | MiniWI.ino is the original proof of concept breadboard version with regular switches. 35 | 36 | MiniWI-lite.ino is a simplified version (no joysticks) for my guest post on the Gordophone blog. 37 | 38 | MiniWI-cap.ino is the capacitive touch version implemented in my first playable prototype. 39 | 40 | MiniWI-cap-pmt.ino is a modification of the touch version to feature portamento (glide) control and a separate potentiometer for setting base octave instead of using sideways motion of joystick to increase range. This reduces instantly playable range but increases the total range of the controller. 41 | 42 | MiniVI-cap.ino is a not yet realized EVI version (Electronic Valve Instrument) based on the Akai EVI1000 and the Steiner MIDI EVI. 43 | 44 | 2016-05-22 45 | 46 | I’ve added some pictures from my Instagram account. Check it out for more pictures from this and my other projects. 47 | 48 | https://www.instagram.com/trasselfrisyr/ 49 | 50 | 2016-05-30 51 | 52 | Project profile for the MiniWI added on Hackaday.io 53 | 54 | https://hackaday.io/project/11843-miniwi-woodwind-midi-controller 55 | 56 | 2016-06-03 57 | 58 | Added optional Casio DH 2nd octave fingerings. Default disabled. Set #define casioMod 1 to set default enabled. Hold octave stick up at power on for manual selection of the setting that is not default. 59 | 60 | 2016-06-12 61 | 62 | Added tested and working version of the new TeensieWI, a simplified version for USB MIDI using the built in capacitive touch sensing in the Teensy LC and breath sensing from the MPX5010GP. Small warning here: the breath sensor output is not limited and could reach values near 5V, while the analog input on the Teensy LC is 3.3V and not rated 5V safe. To reach these levels you’d have to blow really, really hard. If you need to feel safe, go with a Teensy 3.1 or 3.2 as they have 5V tolerant inputs. Only minor alterations needed in the code for use with Teensy 3.x (touch sensing on other pins, some as pads on the back). 63 | 64 | 2017-10-31 65 | 66 | Improved the joystick version of the TeensieWI, now called T.WI, with breath response curves and some other stuff that can be configured at plug-in. Started making these for sale on Tindie. https://www.tindie.com/products/yoe/twi-a-teensy-based-usb-midi-woodwind-controller/ 67 | -------------------------------------------------------------------------------- /T.WI/T.WI-fingering.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trasselfrisyr/MiniWI/539163e4f242e2ff6e4cc9de6d08df4fdd62859f/T.WI/T.WI-fingering.pdf -------------------------------------------------------------------------------- /T.WI/T.WI-settings.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trasselfrisyr/MiniWI/539163e4f242e2ff6e4cc9de6d08df4fdd62859f/T.WI/T.WI-settings.pdf -------------------------------------------------------------------------------- /T.WI/T.WI.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include // for the breath signal LP filtering, https://github.com/edgar-bonet/Filters 3 | 4 | /* 5 | NAME: T.WI 6 | WRITTEN BY: JOHAN BERGLUND 7 | DATE: 2017-10-17 8 | FILE SAVED AS: T.WI.ino 9 | FOR: PJRC Teensy LC and Teensyduino 10 | CLOCK: 48.00 MHz 11 | PROGRAMME FUNCTION: Woodwind Controller using a Freescale MPX5010GP breath sensor, 12 | a PSP1000 joystick and capacitive touch keys. Output to USB MIDI. 13 | 14 | HARDWARE NOTES: 15 | 16 | * The Freescale MPX5010GP pressure sensor output (V OUT) is connected to pin 21(A7). 17 | * (Warning: no voltage limiting before input, can harm Teensy if excessive pressure is applied.) 18 | * 19 | * Sensor pinout 20 | * 1: V OUT (pin with indent) 21 | * 2: GND (to GND pin of Teensy) 22 | * 3: VCC (to 5V pin of Teensy) 23 | * 4: n/c 24 | * 5: n/c 25 | * 6: n/c 26 | * 27 | * Touch sensors are using the Teensy LC built in touchRead function. 28 | * Electrodes connect directly to Teensy pins. 29 | * 30 | * PSP style thumb slide joystick controls pitch bend and modulation. 31 | * Pitch bend and modulation are connected to pins A6 and A0. 32 | * Connections on joystick, bottom view with connectors towards you, L to R: 33 | * 1: to VCC 3.3V 34 | * 2: X (or Y depending on orientation) to analog input 35 | * 3: to GND 36 | * 4: Y (or X depending on orientation) to analog input 37 | * 38 | * PB up 39 | * ^ 40 | * Mod < o > Glide 41 | * v 42 | * PB dn 43 | * 44 | */ 45 | 46 | //_______________________________________________________________________________________________ DECLARATIONS 47 | 48 | #define touch_Thr 1500 // threshold for Teensy touchRead, 1300-1800 49 | #define ON_Thr 300 // Set threshold level before switching ON 50 | #define ON_Delay 20 // Set Delay after ON threshold before velocity is checked (wait for tounging peak) 51 | #define breath_max 2200 // Threshold for maximum breath 52 | #define modsLo_Thr 1600 // Low threshold for mod stick center 53 | #define modsHi_Thr 2480 // High threshold for mod stick center 54 | #define modsMin 960 // PSP joystick min value 55 | #define modsMax 3080 // PSP joystick max value 56 | #define PB_sen1 4096 // Pitch Bend sensitivity 0 to 8192 where 8192 is full pb range, 4096 is half range 57 | #define PB_sen2 683 // Selectable 1/12 PB sense for synths w fixed 12 semitones pb range 58 | #define CCN_Port 5 // Controller number for portamento level 59 | #define CCN_PortOnOff 65// Controller number for portamento on/off 60 | #define portaMax 30 // 1 to 127, max portamento level 61 | 62 | // The three states of our state machine 63 | 64 | // No note is sounding 65 | #define NOTE_OFF 1 66 | 67 | // We've observed a transition from below to above the 68 | // threshold value. We wait a while to see how fast the 69 | // breath velocity is increasing 70 | #define RISE_WAIT 2 71 | 72 | // A note is sounding 73 | #define NOTE_ON 3 74 | 75 | // Send CC data no more than every CC_INTERVAL 76 | // milliseconds 77 | #define CC_INTERVAL 5 78 | 79 | // EEPROM addresses for settings 80 | #define VERSION_ADDR 0 81 | #define TRANS1_ADDR 14 82 | #define MIDI_ADDR 16 83 | #define BREATH_CC_ADDR 18 84 | #define BREATH_AT_ADDR 20 85 | #define PORTAM_ADDR 24 86 | #define PB_ADDR 26 87 | #define EXTRA_ADDR 28 88 | #define TRANS2_ADDR 40 89 | #define BREATHCURVE_ADDR 44 90 | 91 | //"factory" values for settings 92 | #define VERSION 4 93 | #define MIDI_FACTORY 1 // 1-16 94 | #define BREATH_CC_FACTORY 2 // thats CC#2, see ccList 95 | #define BREATH_AT_FACTORY 0 // aftertouch default off 96 | #define PORTAM_FACTORY 2 // 0 - OFF, 1 - ON, 2 - SW 97 | #define PB_FACTORY 0 // 0 - 1/2, 1 - 1/12 98 | #define EXTRA_FACTORY 0 // 0 - Modulation wheel, 1 - Pitch Bend Vibrato 99 | #define BREATHCURVE_FACTORY 2 // 0 to 12 (-4 to +4, S1 to S4) 100 | #define TRANS1_FACTORY 0 // 1 - +2 semitones (C to D, F to G) 101 | #define TRANS2_FACTORY 0 // 1 - -7 semitones (C to F, D to G) "alto mode" 102 | 103 | #define maxSamplesNum 120 104 | 105 | //variables setup 106 | 107 | 108 | static int waveformsTable[maxSamplesNum] = { 109 | // Sine wave 110 | 0x7ff, 0x86a, 0x8d5, 0x93f, 0x9a9, 0xa11, 0xa78, 0xadd, 0xb40, 0xba1, 111 | 0xbff, 0xc5a, 0xcb2, 0xd08, 0xd59, 0xda7, 0xdf1, 0xe36, 0xe77, 0xeb4, 112 | 0xeec, 0xf1f, 0xf4d, 0xf77, 0xf9a, 0xfb9, 0xfd2, 0xfe5, 0xff3, 0xffc, 113 | 0xfff, 0xffc, 0xff3, 0xfe5, 0xfd2, 0xfb9, 0xf9a, 0xf77, 0xf4d, 0xf1f, 114 | 0xeec, 0xeb4, 0xe77, 0xe36, 0xdf1, 0xda7, 0xd59, 0xd08, 0xcb2, 0xc5a, 115 | 0xbff, 0xba1, 0xb40, 0xadd, 0xa78, 0xa11, 0x9a9, 0x93f, 0x8d5, 0x86a, 116 | 0x7ff, 0x794, 0x729, 0x6bf, 0x655, 0x5ed, 0x586, 0x521, 0x4be, 0x45d, 117 | 0x3ff, 0x3a4, 0x34c, 0x2f6, 0x2a5, 0x257, 0x20d, 0x1c8, 0x187, 0x14a, 118 | 0x112, 0xdf, 0xb1, 0x87, 0x64, 0x45, 0x2c, 0x19, 0xb, 0x2, 119 | 0x0, 0x2, 0xb, 0x19, 0x2c, 0x45, 0x64, 0x87, 0xb1, 0xdf, 120 | 0x112, 0x14a, 0x187, 0x1c8, 0x20d, 0x257, 0x2a5, 0x2f6, 0x34c, 0x3a4, 121 | 0x3ff, 0x45d, 0x4be, 0x521, 0x586, 0x5ed, 0x655, 0x6bf, 0x729, 0x794 122 | }; 123 | 124 | 125 | int state; // The state of the state machine 126 | unsigned long ccSendTime = 0L; // The last time we sent CC values 127 | unsigned long breath_on_time = 0L; // Time when breath sensor value went over the ON threshold 128 | int initial_breath_value; // The breath value at the time we observed the transition 129 | 130 | unsigned long lastDebounceTime = 0; // The last time the fingering was changed 131 | unsigned long debounceDelay = 20; // The debounce time; increase if the output flickers 132 | int lastFingering = 0; // Keep the last fingering value for debouncing 133 | 134 | byte MIDIchannel=1; // MIDI channel 1 135 | 136 | unsigned short breathCC; // OFF:MW:BR:VL:EX:MW+:BR+:VL+:EX+ 137 | unsigned short breathAT; 138 | unsigned short portamento; // switching on cc65? just cc5 enabled? SW:ON:OFF 139 | unsigned short curve; // selected curve 140 | unsigned short PB; 141 | unsigned short mod; 142 | unsigned short trans1; 143 | unsigned short trans2; 144 | 145 | byte ccList[9] = {0,1,2,7,11,1,2,7,11}; // OFF, Modulation, Breath, Volume, Expression,(then same sent in hires) 146 | 147 | int breathLevel=0; // breath level (smoothed) not mapped to CC value 148 | int oldbreath=0; 149 | unsigned int oldbreathhires=0; 150 | unsigned int breathValHires=0; 151 | 152 | byte portIsOn=0; // keep track and make sure we send CC with 0 value when off threshold 153 | int oldport=0; 154 | 155 | int pressureSensor; // pressure data from breath sensor, for midi breath cc and breath threshold checks 156 | byte velocitySend; // remapped midi velocity from breath sensor 157 | 158 | int modLevel; 159 | int oldmod=0; 160 | int lfoDepth=2; 161 | int lfoLevel=0; 162 | int lfo=0; 163 | 164 | int pitchBend; 165 | int oldpb=8192; 166 | int PB_sens; 167 | int modCCnumber = 1; 168 | 169 | int fingeredNote; // note calculated from fingering (switches) and octave joystick position 170 | byte activeNote; // note playing 171 | byte startNote=73; // set startNote to C# (change this value in steps of 12 to start in other octaves) 172 | 173 | float filterFreq = 30.0; 174 | 175 | // Key variables, TRUE (1) for pressed, FALSE (0) for not pressed 176 | byte LH1; // Left Hand key 1 (pitch change -2) 177 | // Casio style 2nd octave: If LH1 is not touched when LH2 and LH3 are, pitch change +9 178 | byte LH2; // Left Hand key 2 (with LH1 also pressed pitch change is -2, otherwise -1) 179 | byte LH3; // Left Hand key 3 (pitch change -2) 180 | byte LHp1; // Left Hand pinky key 1 (pitch change +1) 181 | byte RH1; // Right Hand key 1 (with LH3 also pressed pitch change is -2, otherwise -1) 182 | byte RH2; // Right Hand key 2 (pitch change -1) 183 | byte RH3; // Right Hand key 3 (pitch change -2) 184 | byte RHp2; // Right Hand pinky key 2 (pitch change -1) 185 | byte RHp3; // Right Hand pinky key 3 (pitch change -2, in this version -1 if RHp2 is pressed) 186 | byte OCTup; // Octave switch key (pitch change +12) 187 | byte OCTdn; // Octave switch key (pitch change -12) 188 | 189 | 190 | unsigned int curveM4[] = {0,4300,7000,8700,9900,10950,11900,12600,13300,13900,14500,15000,15450,15700,16000,16250,16383}; 191 | unsigned int curveM3[] = {0,2900,5100,6650,8200,9500,10550,11500,12300,13100,13800,14450,14950,15350,15750,16150,16383}; 192 | unsigned int curveM2[] = {0,2000,3600,5000,6450,7850,9000,10100,11100,12100,12900,13700,14400,14950,15500,16000,16383}; 193 | unsigned int curveM1[] = {0,1400,2850,4100,5300,6450,7600,8700,9800,10750,11650,12600,13350,14150,14950,15650,16838}; 194 | unsigned int curveIn[] = {0,1023,2047,3071,4095,5119,6143,7167,8191,9215,10239,11263,12287,13311,14335,15359,16383}; 195 | unsigned int curveP1[] = {0,600,1350,2150,2900,3800,4700,5600,6650,7700,8800,9900,11100,12300,13500,14850,16838}; 196 | unsigned int curveP2[] = {0,400,800,1300,2000,2650,3500,4300,5300,6250,7400,8500,9600,11050,12400,14100,16383}; 197 | unsigned int curveP3[] = {0,200,500,900,1300,1800,2350,3100,3800,4600,5550,6550,8000,9500,11250,13400,16383}; 198 | unsigned int curveP4[] = {0,100,200,400,700,1050,1500,1950,2550,3200,4000,4900,6050,7500,9300,12100,16282}; 199 | unsigned int curveS1[] = {0,600,1350,2150,2900,3800,4700,6000,8700,11000,12400,13400,14300,14950,15500,16000,16383}; 200 | unsigned int curveS2[] = {0,600,1350,2150,2900,4000,6100,9000,11000,12100,12900,13700,14400,14950,15500,16000,16383}; 201 | unsigned int curveS3[] = {0,600,1350,2300,3800,6200,8700,10200,11100,12100,12900,13700,14400,14950,15500,16000,16383}; 202 | unsigned int curveS4[] = {0,600,1700,4000,6600,8550,9700,10550,11400,12200,12900,13700,14400,14950,15500,16000,16383}; 203 | 204 | //_______________________________________________________________________________________________ SETUP 205 | 206 | void setup() { 207 | analogReadResolution(12); // set resolution of ADCs to 12 bit 208 | state = NOTE_OFF; // initialize state machine 209 | pinMode(13,OUTPUT); // use Teensy LED for breath on indication 210 | digitalWrite(13,LOW); 211 | 212 | // if stored settings are not for current version, they are replaced by factory settings 213 | if (readSetting(VERSION_ADDR) != VERSION){ 214 | writeSetting(VERSION_ADDR,VERSION); 215 | writeSetting(MIDI_ADDR,MIDI_FACTORY); 216 | writeSetting(TRANS1_ADDR,TRANS1_FACTORY); 217 | writeSetting(TRANS2_ADDR,TRANS2_FACTORY); 218 | writeSetting(BREATH_CC_ADDR,BREATH_CC_FACTORY); 219 | writeSetting(BREATH_AT_ADDR,BREATH_AT_FACTORY); 220 | writeSetting(PORTAM_ADDR,PORTAM_FACTORY); 221 | writeSetting(PB_ADDR,PB_FACTORY); 222 | writeSetting(EXTRA_ADDR,EXTRA_FACTORY); 223 | writeSetting(BREATHCURVE_ADDR,BREATHCURVE_FACTORY); 224 | } 225 | // read settings from EEPROM 226 | MIDIchannel = readSetting(MIDI_ADDR); 227 | trans1 = readSetting(TRANS1_ADDR); 228 | trans2 = readSetting(TRANS2_ADDR); 229 | breathCC = readSetting(BREATH_CC_ADDR); 230 | breathAT = readSetting(BREATH_AT_ADDR); 231 | portamento = readSetting(PORTAM_ADDR); 232 | PB = readSetting(PB_ADDR); 233 | mod = readSetting(EXTRA_ADDR); 234 | curve = readSetting(BREATHCURVE_ADDR); 235 | 236 | settings(); 237 | 238 | if (PB) PB_sens = PB_sen2; else PB_sens = PB_sen1; 239 | if (trans1) startNote += 2; 240 | if (trans2) startNote -= 7; 241 | } 242 | 243 | //_______________________________________________________________________________________________ MAIN LOOP 244 | 245 | void loop() { 246 | mainLoop(); 247 | } 248 | void mainLoop() { 249 | FilterOnePole breathFilter( LOWPASS, filterFreq ); // create a one pole (RC) lowpass filter 250 | while(1){ 251 | breathFilter.input(analogRead(A7)); 252 | pressureSensor = constrain((int)breathFilter.output(),0,4095); // Get the filtered pressure sensor reading from analog pin A7, input from sensor MP3V5004GP 253 | 254 | if (state == NOTE_OFF) { 255 | if (pressureSensor > ON_Thr) { 256 | // Value has risen above threshold. Move to the ON_Delay 257 | // state. Record time and initial breath value. 258 | breath_on_time = millis(); 259 | initial_breath_value = pressureSensor; 260 | state = RISE_WAIT; // Go to next state 261 | } 262 | } else if (state == RISE_WAIT) { 263 | if (pressureSensor > ON_Thr) { 264 | // Has enough time passed for us to collect our second 265 | // sample? 266 | if (millis() - breath_on_time > ON_Delay) { 267 | // Yes, so calculate MIDI note and velocity, then send a note on event 268 | readSwitches(); 269 | // We should be at tonguing peak, so set velocity based on current pressureSensor value 270 | // If initial value is greater than value after delay, go with initial value, constrain input to keep mapped output within 1 to 127 271 | breathLevel=constrain(max(pressureSensor,initial_breath_value),ON_Thr,breath_max); 272 | breathValHires = breathCurve(map(constrain(breathLevel,ON_Thr,breath_max),ON_Thr,breath_max,0,16383)); 273 | velocitySend = (breathValHires >>7) & 0x007F; 274 | velocitySend = constrain(velocitySend,1,127); 275 | breath(); // send breath data 276 | usbMIDI.sendNoteOn(fingeredNote, velocitySend, MIDIchannel); // send Note On message for new note 277 | digitalWrite(13,HIGH); 278 | activeNote=fingeredNote; 279 | state = NOTE_ON; 280 | } 281 | } else { 282 | // Value fell below threshold before ON_Delay passed. Return to 283 | // NOTE_OFF state (e.g. we're ignoring a short blip of breath) 284 | state = NOTE_OFF; 285 | } 286 | } else if (state == NOTE_ON) { 287 | if (pressureSensor < ON_Thr) { 288 | // Value has fallen below threshold - turn the note off 289 | usbMIDI.sendNoteOff(activeNote, velocitySend, MIDIchannel); // send Note Off message 290 | digitalWrite(13,LOW); 291 | breathLevel=0; 292 | state = NOTE_OFF; 293 | } else { 294 | readSwitches(); 295 | if (fingeredNote != lastFingering){ // 296 | // reset the debouncing timer 297 | lastDebounceTime = millis(); 298 | } 299 | if ((millis() - lastDebounceTime) > debounceDelay) { 300 | // whatever the reading is at, it's been there for longer 301 | // than the debounce delay, so take it as the actual current state 302 | if (fingeredNote != activeNote) { 303 | // Player has moved to a new fingering while still blowing. 304 | // Send a note off for the current note and a note on for 305 | // the new note. 306 | breathValHires = breathCurve(map(constrain(breathLevel,ON_Thr,breath_max),ON_Thr,breath_max,0,16383)); 307 | velocitySend = (breathValHires >>7) & 0x007F; 308 | velocitySend = constrain(velocitySend,1,127); // set new velocity value based on current pressure sensor level 309 | usbMIDI.sendNoteOn(fingeredNote, velocitySend, MIDIchannel); // send Note On message for new note 310 | usbMIDI.sendNoteOff(activeNote, 0, MIDIchannel); // send Note Off message for previous note (legato) 311 | activeNote=fingeredNote; 312 | } 313 | } 314 | } 315 | } 316 | // Is it time to send more CC data? 317 | if (millis() - ccSendTime > CC_INTERVAL) { 318 | // deal with Breath, Pitch Bend and Modulation 319 | breath(); 320 | modulation(); 321 | pitch_bend(); 322 | ccSendTime = millis(); 323 | } 324 | lastFingering=fingeredNote; 325 | } 326 | } 327 | //_______________________________________________________________________________________________ FUNCTIONS 328 | 329 | // non linear mapping function (http://playground.arduino.cc/Main/MultiMap) 330 | // note: the _in array should have increasing values 331 | unsigned int multiMap(unsigned int val, unsigned int* _in, unsigned int* _out, uint8_t size) 332 | { 333 | // take care the value is within range 334 | // val = constrain(val, _in[0], _in[size-1]); 335 | if (val <= _in[0]) return _out[0]; 336 | if (val >= _in[size-1]) return _out[size-1]; 337 | 338 | // search right interval 339 | uint8_t pos = 1; // _in[0] allready tested 340 | while(val > _in[pos]) pos++; 341 | 342 | // this will handle all exact "points" in the _in array 343 | if (val == _in[pos]) return _out[pos]; 344 | 345 | // interpolate in the right segment for the rest 346 | return (val - _in[pos-1]) * (_out[pos] - _out[pos-1]) / (_in[pos] - _in[pos-1]) + _out[pos-1]; 347 | } 348 | 349 | //************************************************************** 350 | 351 | // map breath values to selected curve 352 | unsigned int breathCurve(unsigned int inputVal){ 353 | // 0 to 16383, moving mid value up or down 354 | switch (curve){ 355 | case 0: 356 | // -4 357 | return multiMap(inputVal,curveIn,curveM4,17); 358 | break; 359 | case 1: 360 | // -3 361 | return multiMap(inputVal,curveIn,curveM3,17); 362 | break; 363 | case 2: 364 | // -2 365 | return multiMap(inputVal,curveIn,curveM2,17); 366 | break; 367 | case 3: 368 | // -1 369 | return multiMap(inputVal,curveIn,curveM1,17); 370 | break; 371 | case 4: 372 | // 0, linear 373 | return inputVal; 374 | break; 375 | case 5: 376 | // +1 377 | return multiMap(inputVal,curveIn,curveP1,17); 378 | break; 379 | case 6: 380 | // +2 381 | return multiMap(inputVal,curveIn,curveP2,17); 382 | break; 383 | case 7: 384 | // +3 385 | return multiMap(inputVal,curveIn,curveP3,17); 386 | break; 387 | case 8: 388 | // +4 389 | return multiMap(inputVal,curveIn,curveP4,17); 390 | break; 391 | case 9: 392 | // S1 393 | return multiMap(inputVal,curveIn,curveS1,17); 394 | break; 395 | case 10: 396 | // S2 397 | return multiMap(inputVal,curveIn,curveS2,17); 398 | break; 399 | case 11: 400 | // S3 401 | return multiMap(inputVal,curveIn,curveS3,17); 402 | break; 403 | case 12: 404 | // S4 405 | return multiMap(inputVal,curveIn,curveS4,17); 406 | break; 407 | } 408 | } 409 | 410 | //************************************************************** 411 | 412 | void breath(){ 413 | int breathCCval,breathCCvalFine; 414 | unsigned int breathCCvalHires; 415 | breathLevel = constrain(pressureSensor,ON_Thr,breath_max); 416 | //breathCCval = map(constrain(breathLevel,ON_Thr,breath_max),ON_Thr,breath_max,0,127); 417 | breathCCvalHires = breathCurve(map(constrain(breathLevel,ON_Thr,breath_max),ON_Thr,breath_max,0,16383)); 418 | breathCCval = (breathCCvalHires >>7) & 0x007F; 419 | breathCCvalFine = breathCCvalHires & 0x007F; 420 | 421 | if (breathCCval != oldbreath){ // only send midi data if breath has changed from previous value 422 | if (breathCC){ 423 | // send midi cc 424 | usbMIDI.sendControlChange(ccList[breathCC], breathCCval, MIDIchannel); 425 | } 426 | if (breathAT){ 427 | // send aftertouch 428 | usbMIDI.sendAfterTouch(breathCCval, MIDIchannel); 429 | } 430 | oldbreath = breathCCval; 431 | } 432 | 433 | if (breathCCvalHires != oldbreathhires){ 434 | if (breathCC > 4){ // send high resolution midi 435 | usbMIDI.sendControlChange(ccList[breathCC]+32, breathCCvalFine, MIDIchannel); 436 | } 437 | oldbreathhires = breathCCvalHires; 438 | } 439 | } 440 | 441 | //************************************************************** 442 | 443 | void pitch_bend(){ 444 | pitchBend = analogRead(A0); // read voltage on analog pin A0 445 | if (pitchBend > modsHi_Thr){ 446 | pitchBend = oldpb*0.6+0.4*map(constrain(pitchBend,modsHi_Thr,modsMax),modsHi_Thr,modsMax,8192,(8193 + PB_sens)); // go from 8192 to 16383 (full pb up) when off center threshold going up 447 | } else if (pitchBend < modsLo_Thr){ 448 | pitchBend = oldpb*0.6+0.4*map(constrain(pitchBend,modsMin,modsLo_Thr),modsMin,modsLo_Thr,(8192 - PB_sens),8192); // go from 8192 to 0 (full pb dn) when off center threshold going down 449 | } else { 450 | pitchBend = oldpb*0.6+8192*0.4; // released, so smooth your way back to zero 451 | if ((pitchBend > 8187) && (pitchBend < 8197)) pitchBend = 8192; // 8192 is 0 pitch bend, don't miss it bc of smoothing 452 | } 453 | if (mod || (ccList[breathCC]==1)){ 454 | if (PB) pitchBend += lfoLevel/6; else pitchBend += lfoLevel; 455 | pitchBend=constrain(pitchBend, 0, 16383); 456 | } 457 | if (pitchBend != oldpb){// only send midi data if pitch bend has changed from previous value 458 | usbMIDI.sendPitchBend(pitchBend, MIDIchannel); 459 | oldpb=pitchBend; 460 | } 461 | } 462 | 463 | //*********************************************************** 464 | 465 | void modulation(){ 466 | int modRead = analogRead(A6); // read voltage on analog pin A6 467 | if (modRead < modsLo_Thr){ 468 | modLevel = map(constrain(modRead,modsMin,modsLo_Thr),modsMin,modsLo_Thr,127,0); // go from 0 to full modulation when off center threshold going left(?) 469 | } else { 470 | modLevel = 0; // zero modulation in center position 471 | } 472 | if (modLevel != oldmod){ // only send midi data if modulation has changed from previous value 473 | if (!mod && (ccList[breathCC] != modCCnumber)) usbMIDI.sendControlChange(modCCnumber, modLevel, MIDIchannel); 474 | oldmod=modLevel; 475 | } 476 | if (mod || (ccList[breathCC] == modCCnumber)) { 477 | lfo = waveformsTable[(millis()/2)%maxSamplesNum] - 2047; 478 | lfoLevel = lfo * modLevel / 1024 * lfoDepth; 479 | } 480 | if (portamento && (modRead > modsHi_Thr)) { // if we are enabled and over the threshold, send portamento 481 | if (!portIsOn) { 482 | if (portamento == 2){ // if portamento midi switching is enabled 483 | usbMIDI.sendControlChange(CCN_PortOnOff, 127, MIDIchannel); 484 | } 485 | portIsOn=1; 486 | } 487 | int portCC; 488 | portCC = map(constrain(modRead,modsHi_Thr,modsMax),modsHi_Thr,modsMax,0,portaMax); // go from 0 to full when off center threshold going right(?) 489 | if (portCC!=oldport){ 490 | usbMIDI.sendControlChange(CCN_Port, portCC, MIDIchannel); 491 | } 492 | oldport = portCC; 493 | } else if (portIsOn) { // we have just gone below threshold, so send zero value 494 | usbMIDI.sendControlChange(CCN_Port, 0, MIDIchannel); 495 | if (portamento == 2){ // if portamento midi switching is enabled 496 | usbMIDI.sendControlChange(CCN_PortOnOff, 0, MIDIchannel); 497 | } 498 | portIsOn=0; 499 | oldport = 0; 500 | } 501 | } 502 | 503 | //*********************************************************** 504 | 505 | void writeSetting(byte address, unsigned short value){ 506 | union { 507 | byte v[2]; 508 | unsigned short val; 509 | } data; 510 | data.val = value; 511 | EEPROM.write(address, data.v[0]); 512 | EEPROM.write(address+1, data.v[1]); 513 | } 514 | 515 | //*********************************************************** 516 | 517 | unsigned short readSetting(byte address){ 518 | union { 519 | byte v[2]; 520 | unsigned short val; 521 | } data; 522 | data.v[0] = EEPROM.read(address); 523 | data.v[1] = EEPROM.read(address+1); 524 | return data.val; 525 | } 526 | 527 | //*********************************************************** 528 | 529 | void readSwitches(){ 530 | // Read switches and put value in variables 531 | LH1=touchRead(17)>touch_Thr; 532 | LH2=touchRead(4)>touch_Thr; 533 | LH3=touchRead(3)>touch_Thr; 534 | LHp1=touchRead(18)>touch_Thr; 535 | RH1=touchRead(19)>touch_Thr; 536 | RH2=touchRead(22)>touch_Thr; 537 | RH3=touchRead(23)>touch_Thr; 538 | RHp2=touchRead(1)>touch_Thr; 539 | RHp3=touchRead(0)>touch_Thr; 540 | OCTup=touchRead(15)>touch_Thr; 541 | OCTdn=touchRead(16)>touch_Thr; 542 | //calculate midi note number from pressed keys 543 | fingeredNote=startNote-2*LH1-LH2-(LH2 && LH1)-2*LH3+LHp1-RH1-(RH1 && LH3)-RH2-2*RH3-RHp2-2*RHp3+(RHp2 && RHp3)+12*OCTup-12*OCTdn+9*(!LH1 && LH2 && LH3); 544 | } 545 | 546 | //*********************************************************** 547 | 548 | void numberBlink(byte number){ 549 | for (int i=0; i < number; i++){ 550 | digitalWrite(13,HIGH); 551 | delay(200); 552 | digitalWrite(13,LOW); 553 | delay(200); 554 | } 555 | if (number == 0){ 556 | digitalWrite(13,HIGH); 557 | delay(30); 558 | digitalWrite(13,LOW); 559 | delay(30); 560 | digitalWrite(13,HIGH); 561 | delay(30); 562 | digitalWrite(13,LOW); 563 | delay(30); 564 | digitalWrite(13,HIGH); 565 | delay(30); 566 | digitalWrite(13,LOW); 567 | delay(30); 568 | digitalWrite(13,HIGH); 569 | delay(30); 570 | digitalWrite(13,LOW); 571 | delay(200); 572 | } 573 | } 574 | 575 | //*********************************************************** 576 | 577 | void settings(){ 578 | int y = analogRead(A0); // read joystick y axis, A0 579 | int x = analogRead(A6); // read joystick x axis, A6 580 | byte sel = 0; 581 | byte bin = 0; 582 | byte p1,p2; 583 | 584 | if (y > ((modsHi_Thr+modsMax)/2)) sel = 1; // PB up -> Breath CC/AT settings 585 | else if (y < ((modsLo_Thr+modsMin)/2)) sel = 2; // PB dn -> MIDI CH setting 586 | else if (x > ((modsHi_Thr+modsMax)/2)) sel = 3; // Glide -> Various on/off 587 | else if (x < ((modsLo_Thr+modsMin)/2)) sel = 4; // Mod -> Breath curve setting 588 | 589 | numberBlink(sel); 590 | 591 | delay(1000); 592 | 593 | if (sel){ 594 | // Read switches and put value in variables 595 | bin = (touchRead(19)>touch_Thr) + (touchRead(22)>touch_Thr)*2 + (touchRead(23)>touch_Thr)*4; 596 | p1 = touchRead(1)>touch_Thr; 597 | p2 = touchRead(0)>touch_Thr; 598 | 599 | switch (sel){ 600 | case 1: 601 | breathCC = constrain(bin,0,8); 602 | breathAT = p1; 603 | writeSetting(BREATH_CC_ADDR,breathCC); 604 | writeSetting(BREATH_AT_ADDR,breathAT); 605 | break; 606 | case 2: 607 | MIDIchannel = bin + p1*8 + 1; 608 | writeSetting(MIDI_ADDR,MIDI_FACTORY); 609 | break; 610 | case 3: 611 | if (bitRead(bin,0)){ 612 | if (portamento) portamento = 0; else portamento = 2; // portamento 2 is both switch on/off and portamento value, portamento 1 is just value 613 | writeSetting(PORTAM_ADDR,portamento); 614 | } 615 | if (bitRead(bin,1)){ 616 | PB = !PB; 617 | writeSetting(PB_ADDR,PB); 618 | } 619 | if (bitRead(bin,2)){ 620 | mod = !mod; 621 | writeSetting(EXTRA_ADDR,mod); 622 | } 623 | if (p1){ 624 | trans1 = !trans1; 625 | writeSetting(TRANS1_ADDR,trans1); 626 | } 627 | if (p2){ 628 | trans2 = !trans2; 629 | writeSetting(TRANS2_ADDR,trans2); 630 | } 631 | if ((bin == 7) && p1 && p2){ //restore factory settings 632 | writeSetting(MIDI_ADDR,MIDI_FACTORY); 633 | writeSetting(TRANS1_ADDR,TRANS1_FACTORY); 634 | writeSetting(TRANS2_ADDR,TRANS2_FACTORY); 635 | writeSetting(BREATH_CC_ADDR,BREATH_CC_FACTORY); 636 | writeSetting(BREATH_AT_ADDR,BREATH_AT_FACTORY); 637 | writeSetting(PORTAM_ADDR,PORTAM_FACTORY); 638 | writeSetting(PB_ADDR,PB_FACTORY); 639 | writeSetting(EXTRA_ADDR,EXTRA_FACTORY); 640 | writeSetting(BREATHCURVE_ADDR,BREATHCURVE_FACTORY); 641 | MIDIchannel = readSetting(MIDI_ADDR); 642 | trans1 = readSetting(TRANS1_ADDR); 643 | trans2 = readSetting(TRANS2_ADDR); 644 | breathCC = readSetting(BREATH_CC_ADDR); 645 | breathAT = readSetting(BREATH_AT_ADDR); 646 | portamento = readSetting(PORTAM_ADDR); 647 | PB = readSetting(PB_ADDR); 648 | mod = readSetting(EXTRA_ADDR); 649 | curve = readSetting(BREATHCURVE_ADDR); 650 | } 651 | break; 652 | case 4: 653 | curve = constrain((bin+p1*8),0,12); 654 | writeSetting(BREATHCURVE_ADDR,curve); 655 | } 656 | numberBlink(bin); 657 | delay(1000); 658 | numberBlink(p1); 659 | delay(1000); 660 | numberBlink(p2); 661 | } 662 | } 663 | 664 | 665 | 666 | -------------------------------------------------------------------------------- /T.WI/curves.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trasselfrisyr/MiniWI/539163e4f242e2ff6e4cc9de6d08df4fdd62859f/T.WI/curves.png -------------------------------------------------------------------------------- /T.WI/twi-a4-template.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trasselfrisyr/MiniWI/539163e4f242e2ff6e4cc9de6d08df4fdd62859f/T.WI/twi-a4-template.pdf -------------------------------------------------------------------------------- /T.WI/twi-examples.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trasselfrisyr/MiniWI/539163e4f242e2ff6e4cc9de6d08df4fdd62859f/T.WI/twi-examples.pdf -------------------------------------------------------------------------------- /T.WI/twi-joystick.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trasselfrisyr/MiniWI/539163e4f242e2ff6e4cc9de6d08df4fdd62859f/T.WI/twi-joystick.png -------------------------------------------------------------------------------- /T.WI/twi-schematic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trasselfrisyr/MiniWI/539163e4f242e2ff6e4cc9de6d08df4fdd62859f/T.WI/twi-schematic.png -------------------------------------------------------------------------------- /T.WI/twi-side1.stl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trasselfrisyr/MiniWI/539163e4f242e2ff6e4cc9de6d08df4fdd62859f/T.WI/twi-side1.stl -------------------------------------------------------------------------------- /T.WI/twi-side2.stl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trasselfrisyr/MiniWI/539163e4f242e2ff6e4cc9de6d08df4fdd62859f/T.WI/twi-side2.stl -------------------------------------------------------------------------------- /T.WI/twi-userguide.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trasselfrisyr/MiniWI/539163e4f242e2ff6e4cc9de6d08df4fdd62859f/T.WI/twi-userguide.pdf -------------------------------------------------------------------------------- /TeensieWI-FSR/TeensieWI-FSR.ino: -------------------------------------------------------------------------------- 1 | /* 2 | NAME: TeensieWI 3 | WRITTEN BY: JOHAN BERGLUND 4 | CREDITS: State machine from the Gordophone blog by GORDON GOOD 5 | DATE: 2016-06-09 6 | FILE SAVED AS: TeensieWI.ino 7 | FOR: PJRC Teensy LC and Teensyduino 8 | CLOCK: 48.00 MHz 9 | PROGRAMME FUNCTION: Simple Wind Controller using the Freescale MPX5010GP breath sensor 10 | and capacitive touch keys. Output to USB MIDI. 11 | 12 | HARDWARE NOTES: 13 | 14 | * The Freescale MPX5010GP pressure sensor output (V OUT) is connected to pin 21(A7). 15 | * (Warning: no voltage limiting before input, can harm Teensy if excessive pressure is applied.) 16 | * 17 | * Sensor pinout 18 | * 1: V OUT (pin with indent) 19 | * 2: GND (to GND pin of Teensy) 20 | * 3: VCC (to 5V pin of Teensy) 21 | * 4: n/c 22 | * 5: n/c 23 | * 6: n/c 24 | * 25 | * Touch sensors are using the Teensy LC built in touchRead function. 26 | * Electrodes connect directly to Teensy pins. 27 | * 28 | * Force Sensitive Resistor (DIY or other) connected from 3.3V to pin 14 (A0). 29 | * A resistor is connected from the input to GND. Value about 10K. (Try 1K to 25K if input is too far off). 30 | * Adjust FSR_Thr and FSR_Max to values that makes sense for your FSR. 31 | * 32 | * Slide switch connecting pin 11 to GND for switching FSR between modulation and pitch bend down. 33 | * 34 | */ 35 | 36 | //_______________________________________________________________________________________________ DECLARATIONS 37 | 38 | #define ON_Thr 70 // Set threshold level before switching ON 39 | #define ON_Delay 20 // Set Delay after ON threshold before velocity is checked (wait for tounging peak) 40 | #define breath_max 550 // Threshold for maximum breath 41 | #define FSR_Thr 30 42 | #define FSR_Max 200 43 | #define PB_sens 4095 // Pitch Bend sensitivity 0 to 8191 where 8191 is full pb range, 4095 half 44 | 45 | // The three states of our state machine 46 | 47 | // No note is sounding 48 | #define NOTE_OFF 1 49 | 50 | // We've observed a transition from below to above the 51 | // threshold value. We wait a while to see how fast the 52 | // breath velocity is increasing 53 | #define RISE_WAIT 2 54 | 55 | // A note is sounding 56 | #define NOTE_ON 3 57 | 58 | // Send CC data no more than every CC_INTERVAL 59 | // milliseconds 60 | #define CC_INTERVAL 20 61 | 62 | 63 | //variables setup 64 | 65 | int state; // The state of the state machine 66 | unsigned long ccSendTime = 0L; // The last time we sent CC values 67 | unsigned long breath_on_time = 0L; // Time when breath sensor value went over the ON threshold 68 | int initial_breath_value; // The breath value at the time we observed the transition 69 | 70 | unsigned long lastDebounceTime = 0; // The last time the fingering was changed 71 | unsigned long debounceDelay = 20; // The debounce time; increase if the output flickers 72 | int lastFingering = 0; // Keep the last fingering value for debouncing 73 | 74 | byte MIDIchannel=1; // MIDI channel 1 75 | 76 | int breathLevel=0; // breath level (smoothed) not mapped to CC value 77 | 78 | int pressureSensor; // pressure data from breath sensor, for midi breath cc and breath threshold checks 79 | byte velocity; // remapped midi velocity from breath sensor 80 | 81 | int fingeredNote; // note calculated from fingering (switches) and octave joystick position 82 | byte activeNote; // note playing 83 | byte startNote=73; // set startNote to C# (change this value in steps of 12 to start in other octaves) 84 | byte fsrMode=1; // 0 is bend down, 1 is Modulation 85 | byte fsrIsOn=0; 86 | int fsrModulation; 87 | int fsrBend; 88 | 89 | 90 | // Key variables, TRUE (1) for pressed, FALSE (0) for not pressed 91 | byte LH1; // Left Hand key 1 (pitch change -2) 92 | // Casio style 2nd octave: If LH1 is not touched when LH2 and LH3 are, pitch change +9 93 | byte LH2; // Left Hand key 2 (with LH1 also pressed pitch change is -2, otherwise -1) 94 | byte LH3; // Left Hand key 3 (pitch change -2) 95 | byte LHp1; // Left Hand pinky key 1 (pitch change +1) 96 | byte RH1; // Right Hand key 1 (with LH3 also pressed pitch change is -2, otherwise -1) 97 | byte RH2; // Right Hand key 2 (pitch change -1) 98 | byte RH3; // Right Hand key 3 (pitch change -2) 99 | byte RHp2; // Right Hand pinky key 2 (pitch change -1) 100 | byte RHp3; // Right Hand pinky key 3 (pitch change -2, in this version -1 if RHp2 is pressed) 101 | byte OCTup; // Octave switch key (pitch change +12) 102 | byte OCTdn; // Octave switch key (pitch change -12) 103 | 104 | //_______________________________________________________________________________________________ SETUP 105 | 106 | void setup() { 107 | 108 | state = NOTE_OFF; // initialize state machine 109 | pinMode(11,INPUT_PULLUP); 110 | fsrMode=digitalRead(11); 111 | } 112 | 113 | //_______________________________________________________________________________________________ MAIN LOOP 114 | 115 | void loop() { 116 | 117 | pressureSensor = analogRead(A7); // Get the pressure sensor reading from analog pin A7 118 | 119 | if (state == NOTE_OFF) { 120 | if (pressureSensor > ON_Thr) { 121 | // Value has risen above threshold. Move to the ON_Delay 122 | // state. Record time and initial breath value. 123 | breath_on_time = millis(); 124 | initial_breath_value = pressureSensor; 125 | state = RISE_WAIT; // Go to next state 126 | } 127 | } else if (state == RISE_WAIT) { 128 | if (pressureSensor > ON_Thr) { 129 | // Has enough time passed for us to collect our second 130 | // sample? 131 | if (millis() - breath_on_time > ON_Delay) { 132 | // Yes, so calculate MIDI note and velocity, then send a note on event 133 | readSwitches(); 134 | // We should be at tonguing peak, so set velocity based on current pressureSensor value 135 | // If initial value is greater than value after delay, go with initial value, constrain input to keep mapped output within 1 to 127 136 | velocity = map(constrain(max(pressureSensor,initial_breath_value),ON_Thr,breath_max),ON_Thr,breath_max,1,127); 137 | breathLevel=constrain(max(pressureSensor,initial_breath_value),ON_Thr,breath_max); 138 | breath(); // send breath data 139 | usbMIDI.sendNoteOn(fingeredNote, velocity, MIDIchannel); // send Note On message for new note 140 | activeNote=fingeredNote; 141 | state = NOTE_ON; 142 | } 143 | } else { 144 | // Value fell below threshold before ON_Delay passed. Return to 145 | // NOTE_OFF state (e.g. we're ignoring a short blip of breath) 146 | state = NOTE_OFF; 147 | } 148 | } else if (state == NOTE_ON) { 149 | if (pressureSensor < ON_Thr) { 150 | // Value has fallen below threshold - turn the note off 151 | usbMIDI.sendNoteOff(activeNote, velocity, MIDIchannel); // send Note Off message 152 | breathLevel=0; 153 | state = NOTE_OFF; 154 | } else { 155 | // Is it time to send more CC data? 156 | if (millis() - ccSendTime > CC_INTERVAL) { 157 | // deal with Breath, Pitch Bend and Modulation 158 | breath(); 159 | fsr(); 160 | ccSendTime = millis(); 161 | } 162 | 163 | readSwitches(); 164 | if (fingeredNote != lastFingering){ // 165 | // reset the debouncing timer 166 | lastDebounceTime = millis(); 167 | } 168 | if ((millis() - lastDebounceTime) > debounceDelay) { 169 | // whatever the reading is at, it's been there for longer 170 | // than the debounce delay, so take it as the actual current state 171 | if (fingeredNote != activeNote) { 172 | // Player has moved to a new fingering while still blowing. 173 | // Send a note off for the current note and a note on for 174 | // the new note. 175 | velocity = map(constrain(pressureSensor,ON_Thr,breath_max),ON_Thr,breath_max,7,127); // set new velocity value based on current pressure sensor level 176 | usbMIDI.sendNoteOn(fingeredNote, velocity, MIDIchannel); // send Note On message for new note 177 | usbMIDI.sendNoteOff(activeNote, 0, MIDIchannel); // send Note Off message for previous note (legato) 178 | activeNote=fingeredNote; 179 | } 180 | } 181 | } 182 | } 183 | lastFingering=fingeredNote; 184 | } 185 | //_______________________________________________________________________________________________ FUNCTIONS 186 | 187 | void breath(){ 188 | int breathCC; 189 | breathLevel = breathLevel*0.8+pressureSensor*0.2; // smoothing of breathLevel value 190 | breathCC = map(constrain(breathLevel,ON_Thr,breath_max),ON_Thr,breath_max,0,127); 191 | usbMIDI.sendControlChange(2, breathCC, MIDIchannel); 192 | } 193 | 194 | //*********************************************************** 195 | 196 | void fsr(){ 197 | int fsrReading; 198 | fsrReading=analogRead(A0); 199 | if (fsrReading >= FSR_Thr){ 200 | if (fsrMode){ 201 | // modulation 202 | fsrModulation = map(constrain(fsrReading,FSR_Thr,FSR_Max),FSR_Thr,FSR_Max,0,127); 203 | usbMIDI.sendControlChange(1, fsrModulation, MIDIchannel); 204 | fsrIsOn=1; 205 | } else { 206 | // bend down 207 | fsrBend = map(constrain(fsrReading,FSR_Thr,FSR_Max),FSR_Max,FSR_Thr,(8191 - PB_sens),8192); 208 | usbMIDI.sendPitchBend(fsrBend, MIDIchannel); 209 | fsrIsOn=1; 210 | } 211 | } else if (fsrIsOn){ 212 | //send 0 value 213 | if (fsrMode){ 214 | usbMIDI.sendControlChange(1, 0, MIDIchannel); 215 | } else { 216 | usbMIDI.sendPitchBend(8192, MIDIchannel); // 8192 is 0 pitch bend 217 | } 218 | fsrIsOn=0; 219 | } 220 | } 221 | 222 | //*********************************************************** 223 | 224 | void readSwitches(){ 225 | // Read switches and put value in variables 226 | LH1=touchRead(17)>1500; 227 | LH2=touchRead(4)>1500; 228 | LH3=touchRead(3)>1500; 229 | LHp1=touchRead(18)>1500; 230 | RH1=touchRead(19)>1500; 231 | RH2=touchRead(22)>1500; 232 | RH3=touchRead(23)>1500; 233 | RHp2=touchRead(1)>1000; 234 | RHp3=touchRead(0)>1000; 235 | OCTup=touchRead(15)>1500; 236 | OCTdn=touchRead(16)>1500; 237 | //calculate midi note number from pressed keys 238 | fingeredNote=startNote-2*LH1-LH2-(LH2 && LH1)-2*LH3+LHp1-RH1-(RH1 && LH3)-RH2-2*RH3-RHp2-2*RHp3+(RHp2 && RHp3)+12*OCTup-12*OCTdn+9*(!LH1 && LH2 && LH3); 239 | } 240 | 241 | -------------------------------------------------------------------------------- /TeensieWI-mod/TeensieWI-mod.ino: -------------------------------------------------------------------------------- 1 | /* 2 | NAME: TeensieWI 3 | WRITTEN BY: JOHAN BERGLUND 4 | CREDITS: State machine from the Gordophone blog by GORDON GOOD 5 | DATE: 2016-06-09 6 | FILE SAVED AS: TeensieWI-mod.ino 7 | FOR: PJRC Teensy LC and Teensyduino 8 | CLOCK: 48.00 MHz 9 | PROGRAMME FUNCTION: Simple Wind Controller using the Freescale MPX5010GP breath sensor 10 | and capacitive touch keys. Output to USB MIDI. 11 | 12 | HARDWARE NOTES: 13 | 14 | * The Freescale MPX5010GP pressure sensor output (V OUT) is connected to pin 21(A7). 15 | * (Warning: no voltage limiting before input, can harm Teensy if excessive pressure is applied.) 16 | * 17 | * Sensor pinout 18 | * 1: V OUT (pin with indent) 19 | * 2: GND (to GND pin of Teensy) 20 | * 3: VCC (to 5V pin of Teensy) 21 | * 4: n/c 22 | * 5: n/c 23 | * 6: n/c 24 | * 25 | * Touch sensors are using the Teensy LC built in touchRead function. 26 | * Electrodes connect directly to Teensy pins. 27 | * 28 | * PSP style thumb slide joystick controls pitch bend and modulation. 29 | * Pitch bend and modulation are connected to pins A6 and A0. 30 | * Connections on joystick, bottom view with connectors towards you, L to R: 31 | * 1: to VCC 3.3V 32 | * 2: X (or Y depending on orientation) to analog input 33 | * 3: to GND 34 | * 4: Y (or X depending on orientation) to analog input 35 | * 36 | * PB up 37 | * ^ 38 | * Mod < o > Mod 39 | * v 40 | * PB dn 41 | * 42 | */ 43 | 44 | //_______________________________________________________________________________________________ DECLARATIONS 45 | 46 | #define ON_Thr 70 // Set threshold level before switching ON 47 | #define ON_Delay 20 // Set Delay after ON threshold before velocity is checked (wait for tounging peak) 48 | #define breath_max 550 // Threshold for maximum breath 49 | #define modsLo_Thr 411 // Low threshold for mod stick center 50 | #define modsHi_Thr 611 // High threshold for mod stick center 51 | #define modsMin 240 // PSP joystick min value 52 | #define modsMax 770 // PSP joystick max value 53 | #define PB_sens 4096 // Pitch Bend sensitivity 0 to 8192 where 8192 is full pb range, 4096 is half range 54 | 55 | 56 | 57 | // The three states of our state machine 58 | 59 | // No note is sounding 60 | #define NOTE_OFF 1 61 | 62 | // We've observed a transition from below to above the 63 | // threshold value. We wait a while to see how fast the 64 | // breath velocity is increasing 65 | #define RISE_WAIT 2 66 | 67 | // A note is sounding 68 | #define NOTE_ON 3 69 | 70 | // Send CC data no more than every CC_INTERVAL 71 | // milliseconds 72 | #define CC_INTERVAL 5 73 | 74 | 75 | //variables setup 76 | 77 | int state; // The state of the state machine 78 | unsigned long ccSendTime = 0L; // The last time we sent CC values 79 | unsigned long breath_on_time = 0L; // Time when breath sensor value went over the ON threshold 80 | int initial_breath_value; // The breath value at the time we observed the transition 81 | 82 | unsigned long lastDebounceTime = 0; // The last time the fingering was changed 83 | unsigned long debounceDelay = 20; // The debounce time; increase if the output flickers 84 | int lastFingering = 0; // Keep the last fingering value for debouncing 85 | 86 | byte MIDIchannel=1; // MIDI channel 1 87 | 88 | int breathLevel=0; // breath level (smoothed) not mapped to CC value 89 | int oldbreath=0; 90 | 91 | int pressureSensor; // pressure data from breath sensor, for midi breath cc and breath threshold checks 92 | byte velocity; // remapped midi velocity from breath sensor 93 | 94 | int modLevel; 95 | int oldmod=0; 96 | 97 | int pitchBend; 98 | int oldpb=8192; 99 | 100 | int fingeredNote; // note calculated from fingering (switches) and octave joystick position 101 | byte activeNote; // note playing 102 | byte startNote=73; // set startNote to C# (change this value in steps of 12 to start in other octaves) 103 | 104 | 105 | // Key variables, TRUE (1) for pressed, FALSE (0) for not pressed 106 | byte LH1; // Left Hand key 1 (pitch change -2) 107 | // Casio style 2nd octave: If LH1 is not touched when LH2 and LH3 are, pitch change +9 108 | byte LH2; // Left Hand key 2 (with LH1 also pressed pitch change is -2, otherwise -1) 109 | byte LH3; // Left Hand key 3 (pitch change -2) 110 | byte LHp1; // Left Hand pinky key 1 (pitch change +1) 111 | byte RH1; // Right Hand key 1 (with LH3 also pressed pitch change is -2, otherwise -1) 112 | byte RH2; // Right Hand key 2 (pitch change -1) 113 | byte RH3; // Right Hand key 3 (pitch change -2) 114 | byte RHp2; // Right Hand pinky key 2 (pitch change -1) 115 | byte RHp3; // Right Hand pinky key 3 (pitch change -2, in this version -1 if RHp2 is pressed) 116 | byte OCTup; // Octave switch key (pitch change +12) 117 | byte OCTdn; // Octave switch key (pitch change -12) 118 | 119 | //_______________________________________________________________________________________________ SETUP 120 | 121 | void setup() { 122 | 123 | state = NOTE_OFF; // initialize state machine 124 | pinMode(13,OUTPUT); 125 | digitalWrite(13,LOW); 126 | } 127 | 128 | //_______________________________________________________________________________________________ MAIN LOOP 129 | 130 | void loop() { 131 | 132 | pressureSensor = analogRead(A7); // Get the pressure sensor reading from analog pin A7 133 | 134 | if (state == NOTE_OFF) { 135 | if (pressureSensor > ON_Thr) { 136 | // Value has risen above threshold. Move to the ON_Delay 137 | // state. Record time and initial breath value. 138 | breath_on_time = millis(); 139 | initial_breath_value = pressureSensor; 140 | state = RISE_WAIT; // Go to next state 141 | } 142 | } else if (state == RISE_WAIT) { 143 | if (pressureSensor > ON_Thr) { 144 | // Has enough time passed for us to collect our second 145 | // sample? 146 | if (millis() - breath_on_time > ON_Delay) { 147 | // Yes, so calculate MIDI note and velocity, then send a note on event 148 | readSwitches(); 149 | // We should be at tonguing peak, so set velocity based on current pressureSensor value 150 | // If initial value is greater than value after delay, go with initial value, constrain input to keep mapped output within 1 to 127 151 | velocity = map(constrain(max(pressureSensor,initial_breath_value),ON_Thr,breath_max),ON_Thr,breath_max,1,127); 152 | breathLevel=constrain(max(pressureSensor,initial_breath_value),ON_Thr,breath_max); 153 | breath(); // send breath data 154 | usbMIDI.sendNoteOn(fingeredNote, velocity, MIDIchannel); // send Note On message for new note 155 | digitalWrite(13,HIGH); 156 | activeNote=fingeredNote; 157 | state = NOTE_ON; 158 | } 159 | } else { 160 | // Value fell below threshold before ON_Delay passed. Return to 161 | // NOTE_OFF state (e.g. we're ignoring a short blip of breath) 162 | state = NOTE_OFF; 163 | } 164 | } else if (state == NOTE_ON) { 165 | if (pressureSensor < ON_Thr) { 166 | // Value has fallen below threshold - turn the note off 167 | usbMIDI.sendNoteOff(activeNote, velocity, MIDIchannel); // send Note Off message 168 | digitalWrite(13,LOW); 169 | breathLevel=0; 170 | state = NOTE_OFF; 171 | } else { 172 | readSwitches(); 173 | if (fingeredNote != lastFingering){ // 174 | // reset the debouncing timer 175 | lastDebounceTime = millis(); 176 | } 177 | if ((millis() - lastDebounceTime) > debounceDelay) { 178 | // whatever the reading is at, it's been there for longer 179 | // than the debounce delay, so take it as the actual current state 180 | if (fingeredNote != activeNote) { 181 | // Player has moved to a new fingering while still blowing. 182 | // Send a note off for the current note and a note on for 183 | // the new note. 184 | velocity = map(constrain(pressureSensor,ON_Thr,breath_max),ON_Thr,breath_max,7,127); // set new velocity value based on current pressure sensor level 185 | usbMIDI.sendNoteOn(fingeredNote, velocity, MIDIchannel); // send Note On message for new note 186 | usbMIDI.sendNoteOff(activeNote, 0, MIDIchannel); // send Note Off message for previous note (legato) 187 | activeNote=fingeredNote; 188 | } 189 | } 190 | } 191 | } 192 | // Is it time to send more CC data? 193 | if (millis() - ccSendTime > CC_INTERVAL) { 194 | // deal with Breath, Pitch Bend and Modulation 195 | breath(); 196 | pitch_bend(); 197 | modulation(); 198 | ccSendTime = millis(); 199 | } 200 | lastFingering=fingeredNote; 201 | } 202 | //_______________________________________________________________________________________________ FUNCTIONS 203 | 204 | void breath(){ 205 | int breathCC; 206 | breathLevel = breathLevel*0.8+pressureSensor*0.2; // smoothing of breathLevel value 207 | breathCC = map(constrain(breathLevel,ON_Thr,breath_max),ON_Thr,breath_max,0,127); 208 | if (breathCC != oldbreath){ // only send midi data if breath has changed from previous value 209 | usbMIDI.sendControlChange(2, breathCC, MIDIchannel); 210 | oldbreath = breathCC; 211 | } 212 | } 213 | 214 | //************************************************************** 215 | 216 | void pitch_bend(){ 217 | pitchBend = analogRead(A0); // read voltage on analog pin A0 218 | if (pitchBend > modsHi_Thr){ 219 | pitchBend = oldpb*0.6+0.4*map(constrain(pitchBend,modsHi_Thr,modsMax),modsHi_Thr,modsMax,8192,(8193 + PB_sens)); // go from 8192 to 16383 (full pb up) when off center threshold going up 220 | } else if (pitchBend < modsLo_Thr){ 221 | pitchBend = oldpb*0.6+0.4*map(constrain(pitchBend,modsMin,modsLo_Thr),modsMin,modsLo_Thr,(8192 - PB_sens),8192); // go from 8192 to 0 (full pb dn) when off center threshold going down 222 | } else { 223 | pitchBend = oldpb*0.6+8192*0.4; // released, so smooth your way back to zero 224 | if ((pitchBend > 8187) && (pitchBend < 8197)) pitchBend = 8192; // 8192 is 0 pitch bend, don't miss it bc of smoothing 225 | } 226 | if (pitchBend != oldpb){// only send midi data if pitch bend has changed from previous value 227 | usbMIDI.sendPitchBend(pitchBend, MIDIchannel); 228 | oldpb=pitchBend; 229 | } 230 | } 231 | 232 | //*********************************************************** 233 | 234 | void modulation(){ 235 | modLevel = analogRead(A6); // read voltage on analog pin A6 236 | if (modLevel > modsHi_Thr){ 237 | modLevel = map(constrain(modLevel,modsHi_Thr,modsMax),modsHi_Thr,modsMax,0,127); // go from 0 to full modulation when off center threshold going right(?) 238 | } else if (modLevel < modsLo_Thr){ 239 | modLevel = map(constrain(modLevel,modsMin,modsLo_Thr),modsMin,modsLo_Thr,127,0); // go from 0 to full modulation when off center threshold going left(?) 240 | } else { 241 | modLevel = 0; // zero modulation in center position 242 | } 243 | if (modLevel != oldmod){ // only send midi data if modulation has changed from previous value 244 | usbMIDI.sendControlChange(1, modLevel, MIDIchannel); 245 | oldmod=modLevel; 246 | } 247 | } 248 | 249 | //*********************************************************** 250 | 251 | void readSwitches(){ 252 | // Read switches and put value in variables 253 | LH1=touchRead(17)>1500; 254 | LH2=touchRead(4)>1500; 255 | LH3=touchRead(3)>1500; 256 | LHp1=touchRead(18)>1500; 257 | RH1=touchRead(19)>1500; 258 | RH2=touchRead(22)>1500; 259 | RH3=touchRead(23)>1500; 260 | RHp2=touchRead(1)>1500; 261 | RHp3=touchRead(0)>1500; 262 | OCTup=touchRead(15)>1500; 263 | OCTdn=touchRead(16)>1500; 264 | //calculate midi note number from pressed keys 265 | fingeredNote=startNote-2*LH1-LH2-(LH2 && LH1)-2*LH3+LHp1-RH1-(RH1 && LH3)-RH2-2*RH3-RHp2-2*RHp3+(RHp2 && RHp3)+12*OCTup-12*OCTdn+9*(!LH1 && LH2 && LH3); 266 | } 267 | 268 | 269 | 270 | -------------------------------------------------------------------------------- /TeensieWI-mod/twmod-schematic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trasselfrisyr/MiniWI/539163e4f242e2ff6e4cc9de6d08df4fdd62859f/TeensieWI-mod/twmod-schematic.png -------------------------------------------------------------------------------- /TeensieWI-mod/twmod.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trasselfrisyr/MiniWI/539163e4f242e2ff6e4cc9de6d08df4fdd62859f/TeensieWI-mod/twmod.png -------------------------------------------------------------------------------- /TeensieWI/TeensieWI-fingering.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trasselfrisyr/MiniWI/539163e4f242e2ff6e4cc9de6d08df4fdd62859f/TeensieWI/TeensieWI-fingering.png -------------------------------------------------------------------------------- /TeensieWI/TeensieWI-schematic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trasselfrisyr/MiniWI/539163e4f242e2ff6e4cc9de6d08df4fdd62859f/TeensieWI/TeensieWI-schematic.png -------------------------------------------------------------------------------- /TeensieWI/TeensieWI.ino: -------------------------------------------------------------------------------- 1 | /* 2 | NAME: TeensieWI 3 | WRITTEN BY: JOHAN BERGLUND 4 | CREDITS: State machine from the Gordophone blog by GORDON GOOD 5 | DATE: 2016-06-09 6 | FILE SAVED AS: TeensieWI.ino 7 | FOR: PJRC Teensy LC and Teensyduino 8 | CLOCK: 48.00 MHz 9 | PROGRAMME FUNCTION: Simple Wind Controller using the Freescale MPX5010GP breath sensor 10 | and capacitive touch keys. Output to USB MIDI. 11 | 12 | HARDWARE NOTES: 13 | 14 | * The Freescale MPX5010GP pressure sensor output (V OUT) is connected to pin 21(A7). 15 | * (Warning: no voltage limiting before input, can harm Teensy if excessive pressure is applied.) 16 | * 17 | * Sensor pinout 18 | * 1: V OUT (pin with indent) 19 | * 2: GND (to GND pin of Teensy) 20 | * 3: VCC (to 5V pin of Teensy) 21 | * 4: n/c 22 | * 5: n/c 23 | * 6: n/c 24 | * 25 | * Touch sensors are using the Teensy LC built in touchRead function. 26 | * Electrodes connect directly to Teensy pins. 27 | * 28 | */ 29 | 30 | //_______________________________________________________________________________________________ DECLARATIONS 31 | 32 | #define ON_Thr 70 // Set threshold level before switching ON 33 | #define ON_Delay 20 // Set Delay after ON threshold before velocity is checked (wait for tounging peak) 34 | #define breath_max 550 // Threshold for maximum breath 35 | 36 | // The three states of our state machine 37 | 38 | // No note is sounding 39 | #define NOTE_OFF 1 40 | 41 | // We've observed a transition from below to above the 42 | // threshold value. We wait a while to see how fast the 43 | // breath velocity is increasing 44 | #define RISE_WAIT 2 45 | 46 | // A note is sounding 47 | #define NOTE_ON 3 48 | 49 | // Send CC data no more than every CC_INTERVAL 50 | // milliseconds 51 | #define CC_INTERVAL 20 52 | 53 | 54 | //variables setup 55 | 56 | int state; // The state of the state machine 57 | unsigned long ccSendTime = 0L; // The last time we sent CC values 58 | unsigned long breath_on_time = 0L; // Time when breath sensor value went over the ON threshold 59 | int initial_breath_value; // The breath value at the time we observed the transition 60 | 61 | unsigned long lastDebounceTime = 0; // The last time the fingering was changed 62 | unsigned long debounceDelay = 20; // The debounce time; increase if the output flickers 63 | int lastFingering = 0; // Keep the last fingering value for debouncing 64 | 65 | byte MIDIchannel=1; // MIDI channel 1 66 | 67 | int breathLevel=0; // breath level (smoothed) not mapped to CC value 68 | 69 | int pressureSensor; // pressure data from breath sensor, for midi breath cc and breath threshold checks 70 | byte velocity; // remapped midi velocity from breath sensor 71 | 72 | int fingeredNote; // note calculated from fingering (switches) and octave joystick position 73 | byte activeNote; // note playing 74 | byte startNote=73; // set startNote to C# (change this value in steps of 12 to start in other octaves) 75 | 76 | 77 | // Key variables, TRUE (1) for pressed, FALSE (0) for not pressed 78 | byte LH1; // Left Hand key 1 (pitch change -2) 79 | // Casio style 2nd octave: If LH1 is not touched when LH2 and LH3 are, pitch change +9 80 | byte LH2; // Left Hand key 2 (with LH1 also pressed pitch change is -2, otherwise -1) 81 | byte LH3; // Left Hand key 3 (pitch change -2) 82 | byte LHp1; // Left Hand pinky key 1 (pitch change +1) 83 | byte RH1; // Right Hand key 1 (with LH3 also pressed pitch change is -2, otherwise -1) 84 | byte RH2; // Right Hand key 2 (pitch change -1) 85 | byte RH3; // Right Hand key 3 (pitch change -2) 86 | byte RHp2; // Right Hand pinky key 2 (pitch change -1) 87 | byte RHp3; // Right Hand pinky key 3 (pitch change -2, in this version -1 if RHp2 is pressed) 88 | byte OCTup; // Octave switch key (pitch change +12) 89 | byte OCTdn; // Octave switch key (pitch change -12) 90 | 91 | //_______________________________________________________________________________________________ SETUP 92 | 93 | void setup() { 94 | 95 | state = NOTE_OFF; // initialize state machine 96 | 97 | } 98 | 99 | //_______________________________________________________________________________________________ MAIN LOOP 100 | 101 | void loop() { 102 | 103 | pressureSensor = analogRead(A7); // Get the pressure sensor reading from analog pin A7 104 | 105 | if (state == NOTE_OFF) { 106 | if (pressureSensor > ON_Thr) { 107 | // Value has risen above threshold. Move to the ON_Delay 108 | // state. Record time and initial breath value. 109 | breath_on_time = millis(); 110 | initial_breath_value = pressureSensor; 111 | state = RISE_WAIT; // Go to next state 112 | } 113 | } else if (state == RISE_WAIT) { 114 | if (pressureSensor > ON_Thr) { 115 | // Has enough time passed for us to collect our second 116 | // sample? 117 | if (millis() - breath_on_time > ON_Delay) { 118 | // Yes, so calculate MIDI note and velocity, then send a note on event 119 | readSwitches(); 120 | // We should be at tonguing peak, so set velocity based on current pressureSensor value 121 | // If initial value is greater than value after delay, go with initial value, constrain input to keep mapped output within 1 to 127 122 | velocity = map(constrain(max(pressureSensor,initial_breath_value),ON_Thr,breath_max),ON_Thr,breath_max,1,127); 123 | breathLevel=constrain(max(pressureSensor,initial_breath_value),ON_Thr,breath_max); 124 | breath(); // send breath data 125 | usbMIDI.sendNoteOn(fingeredNote, velocity, MIDIchannel); // send Note On message for new note 126 | activeNote=fingeredNote; 127 | state = NOTE_ON; 128 | } 129 | } else { 130 | // Value fell below threshold before ON_Delay passed. Return to 131 | // NOTE_OFF state (e.g. we're ignoring a short blip of breath) 132 | state = NOTE_OFF; 133 | } 134 | } else if (state == NOTE_ON) { 135 | if (pressureSensor < ON_Thr) { 136 | // Value has fallen below threshold - turn the note off 137 | usbMIDI.sendNoteOff(activeNote, velocity, MIDIchannel); // send Note Off message 138 | breathLevel=0; 139 | state = NOTE_OFF; 140 | } else { 141 | // Is it time to send more CC data? 142 | if (millis() - ccSendTime > CC_INTERVAL) { 143 | // deal with Breath, Pitch Bend and Modulation 144 | breath(); 145 | ccSendTime = millis(); 146 | } 147 | 148 | readSwitches(); 149 | if (fingeredNote != lastFingering){ // 150 | // reset the debouncing timer 151 | lastDebounceTime = millis(); 152 | } 153 | if ((millis() - lastDebounceTime) > debounceDelay) { 154 | // whatever the reading is at, it's been there for longer 155 | // than the debounce delay, so take it as the actual current state 156 | if (fingeredNote != activeNote) { 157 | // Player has moved to a new fingering while still blowing. 158 | // Send a note off for the current note and a note on for 159 | // the new note. 160 | velocity = map(constrain(pressureSensor,ON_Thr,breath_max),ON_Thr,breath_max,7,127); // set new velocity value based on current pressure sensor level 161 | usbMIDI.sendNoteOn(fingeredNote, velocity, MIDIchannel); // send Note On message for new note 162 | usbMIDI.sendNoteOff(activeNote, 0, MIDIchannel); // send Note Off message for previous note (legato) 163 | activeNote=fingeredNote; 164 | } 165 | } 166 | } 167 | } 168 | lastFingering=fingeredNote; 169 | } 170 | //_______________________________________________________________________________________________ FUNCTIONS 171 | 172 | void breath(){ 173 | int breathCC; 174 | breathLevel = breathLevel*0.8+pressureSensor*0.2; // smoothing of breathLevel value 175 | breathCC = map(constrain(breathLevel,ON_Thr,breath_max),ON_Thr,breath_max,0,127); 176 | usbMIDI.sendControlChange(2, breathCC, MIDIchannel); 177 | } 178 | 179 | //*********************************************************** 180 | 181 | void readSwitches(){ 182 | // Read switches and put value in variables 183 | LH1=touchRead(17)>1500; 184 | LH2=touchRead(4)>1500; 185 | LH3=touchRead(3)>1500; 186 | LHp1=touchRead(18)>1500; 187 | RH1=touchRead(19)>1500; 188 | RH2=touchRead(22)>1500; 189 | RH3=touchRead(23)>1500; 190 | RHp2=touchRead(1)>1500; 191 | RHp3=touchRead(0)>1500; 192 | OCTup=touchRead(15)>1500; 193 | OCTdn=touchRead(16)>1500; 194 | //calculate midi note number from pressed keys 195 | fingeredNote=startNote-2*LH1-LH2-(LH2 && LH1)-2*LH3+LHp1-RH1-(RH1 && LH3)-RH2-2*RH3-RHp2-2*RHp3+(RHp2 && RHp3)+12*OCTup-12*OCTdn+9*(!LH1 && LH2 && LH3); 196 | } 197 | 198 | --------------------------------------------------------------------------------