{"id":626,"date":"2023-03-17T22:24:01","date_gmt":"2023-03-17T22:24:01","guid":{"rendered":"http:\/\/bussigel.com\/newinstruments\/?page_id=626"},"modified":"2025-10-21T03:57:59","modified_gmt":"2025-10-21T07:57:59","slug":"digital-inputs","status":"publish","type":"page","link":"https:\/\/bussigel.com\/sonicarts\/digital-inputs\/","title":{"rendered":"Digital Inputs"},"content":{"rendered":"\n<div style=\"height:41px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">Digital inputs send a binary signal to the computer, which we can think of as ON or OFF. Digital Inputs are good for triggering events (like a sound or video file) or playing a key (like on a keyboard) or changing the state of something.&nbsp; Here we will connect a pushbutton and a switch, the most common types of digital inputs.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"789\" src=\"http:\/\/bussigel.com\/sonicarts\/wp-content\/uploads\/2025\/09\/1.png\" alt=\"\" class=\"wp-image-745\" style=\"width:430px;height:auto\" srcset=\"https:\/\/bussigel.com\/sonicarts\/wp-content\/uploads\/2025\/09\/1.png 1024w, https:\/\/bussigel.com\/sonicarts\/wp-content\/uploads\/2025\/09\/1-300x231.png 300w, https:\/\/bussigel.com\/sonicarts\/wp-content\/uploads\/2025\/09\/1-768x592.png 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n<\/div>\n\n\n<p class=\"wp-block-paragraph\">This picture above shows how to a momentary button. The button pictured above is a pretty standard button with two legs, but buttons and switches come in all kinds of shapes and forms \u2014 the connection method remains the same! Because the button is simply making and breaking a connection, it doesn\u2019t matter which wire goes to which leg. Just attach one leg to ground (GND) and one leg to pin 5. Here is what the code looks like for a digital input\u2026<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ Create an array of NoteButton objects that send \n\/\/ MIDI note events when a push button or toggle is pressed\/released \nNoteButton buttons&#91;]{ \n{5, 61}, \/\/ Push button on pin 5 \n{6, 62}, \/\/ Toggle switch on pin 6 \n};<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">In the code, first we create a NoteButton object and then we say that we are going to create a bunch of them by creating a button array \u2014 buttons[]. All of this initial code will stay the same, regardless of how many buttons, switches, or other digital inputs you add! On the next line we specify a pin number, 5, and tell the arduino what to do when pin 5 is connected to ground, meaning the button is pressed. In this case, the arduino sends a message to play MIDI note 61. So, if you have a midi track enabled in a DAW, you will hear note 61. In Max, you can use this note information to play a note, but you can also use it to start a process or to turn something on and off!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This next example shows how to connect a button and a toggle switch, both digital inputs. Note that the toggle switch has 3 legs, not two like the button. By toggling the switch back and forth, you are connecting the middle leg to one or the other outer legs. So, when you connect a toggle switch, connect one wire to the middle leg and one wire to one of the outside legs. Also, not that instead of connecting both components directed to ground, I have connected the ground legs together, so that I only need to connect to ground on the board once!<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"962\" src=\"http:\/\/bussigel.com\/sonicarts\/wp-content\/uploads\/2025\/09\/2.png\" alt=\"\" class=\"wp-image-744\" style=\"width:420px;height:auto\" srcset=\"https:\/\/bussigel.com\/sonicarts\/wp-content\/uploads\/2025\/09\/2.png 1024w, https:\/\/bussigel.com\/sonicarts\/wp-content\/uploads\/2025\/09\/2-300x282.png 300w, https:\/\/bussigel.com\/sonicarts\/wp-content\/uploads\/2025\/09\/2-768x722.png 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n<\/div>\n\n\n<p class=\"wp-block-paragraph\">The code above works with both of these digital inputs \u2014 the outer leg of the toggle switch is connected to pin 6, and the middle leg is connected to ground through the ground leg on the button. Try to add more digital inputs to your interface. Also try other kinds of digital switches \u2014 tilt switches are fun, but you could also simply connect and disconnect the two wires, allowing for all kinds of sculptural possibilities.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Now, if you want to use 4 digital inputs instead of 2, we need to modify the Arduino code a bit. Take a look&#8230; <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ Create an array of NoteButton objects that send \n\/\/ MIDI note events when a push button or toggle is pressed\/released \nNoteButton buttons&#91;]{ \n{5, 61}, \/\/ Push button on pin 5 \n{6, 62}, \/\/ Toggle switch on pin 6 \n{7, 63}, \/\/ Two pieces of wire on pin 7 (and GND)\n{8, 64}, \/\/ slide switch on pin 8 \n}; <\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You can specify something like 15 digital inputs (this will cut into the pin allotment for analog sensors and acuators. Take a look at the Pinout diagram for the Arduino Pro Micro to understand which pins can function as digital inputs (most of them can!)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"810\" height=\"514\" src=\"https:\/\/bussigel.com\/sonicarts\/wp-content\/uploads\/2025\/10\/image-1.png\" alt=\"\" class=\"wp-image-807\" srcset=\"https:\/\/bussigel.com\/sonicarts\/wp-content\/uploads\/2025\/10\/image-1.png 810w, https:\/\/bussigel.com\/sonicarts\/wp-content\/uploads\/2025\/10\/image-1-300x190.png 300w, https:\/\/bussigel.com\/sonicarts\/wp-content\/uploads\/2025\/10\/image-1-768x487.png 768w\" sizes=\"auto, (max-width: 810px) 100vw, 810px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The purple pins can be used as digital inputs and outputs, the green pins are able to be used as analog inputs, and the squiggle lines represent PWM, we&#8217;ll talk about that later on.  <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Digital inputs send a binary signal to the computer, which we can think of as ON or OFF. Digital Inputs are good for triggering events (like a sound or video file) or playing a key (like on a keyboard) or changing the state of something.&nbsp; Here we will connect a pushbutton and a switch, the &hellip; <a href=\"https:\/\/bussigel.com\/sonicarts\/digital-inputs\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Digital Inputs<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-626","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/bussigel.com\/sonicarts\/wp-json\/wp\/v2\/pages\/626","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bussigel.com\/sonicarts\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/bussigel.com\/sonicarts\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/bussigel.com\/sonicarts\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bussigel.com\/sonicarts\/wp-json\/wp\/v2\/comments?post=626"}],"version-history":[{"count":2,"href":"https:\/\/bussigel.com\/sonicarts\/wp-json\/wp\/v2\/pages\/626\/revisions"}],"predecessor-version":[{"id":813,"href":"https:\/\/bussigel.com\/sonicarts\/wp-json\/wp\/v2\/pages\/626\/revisions\/813"}],"wp:attachment":[{"href":"https:\/\/bussigel.com\/sonicarts\/wp-json\/wp\/v2\/media?parent=626"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}