{"id":854,"date":"2009-11-25T20:24:50","date_gmt":"2009-11-26T02:24:50","guid":{"rendered":"http:\/\/alliwalk.com\/blog\/?p=854"},"modified":"2009-12-13T16:54:01","modified_gmt":"2009-12-13T22:54:01","slug":"phys-comp-icm-finals-a-nice-combination","status":"publish","type":"post","link":"https:\/\/alliwalk.com\/blog\/2009\/11\/phys-comp-icm-finals-a-nice-combination\/","title":{"rendered":"Using Arduino and Processing together"},"content":{"rendered":"<p>Today I got up early and fooled around in Processing&#8230;for hours. I was playing with the Minim sound library, which I&#8217;d planned to use for my Intro to Computing Media project, an mp3 player. After sitting around for so long, I could how I was getting both noticeably older in age, but also wiser about Minim. Why sit around and program something completely different when I could put the two together? Well, my fear with combing my two projects, ICM and PhysComp, was that I&#8217;d skimp out on one or the other and not fully challenge myself. However, due to the MEX conference &#8211; to be blogged about soon! &#8211; my schedule is shorter than I&#8217;d like. Something&#8217;s gotta give. Sadly, it&#8217;ll have to be a little bit here and there on my projects.<\/p>\n<p>Anyway, today, I worked on combining my Arduino code and my Processing code using serial output to play a song. Before discussing this, a little recap:<\/p>\n<p>Create the code to turn on\/off LEDs set at a threshold. Using the map() function and an if\/else statement, I can now reliably turn off and on an LED as though it were a switch.<br \/>\nHere&#8217;s the code for the mapping and if\/else statement part:<\/p>\n<pre>phoVal1 = analogRead(phoPin1);\r\n\u00a0 \/\/map the photocell values and turn on the light\r\n\u00a0 phoVal1 = map(phoVal1, 0, 255, 255, 0);\r\n\u00a0 if (phoVal1&gt;=0) {\r\n\u00a0\u00a0\u00a0 digitalWrite(pholed1,HIGH);\r\n\u00a0 }\r\n\u00a0 else{\r\n\u00a0\u00a0\u00a0 digitalWrite(pholed1,LOW);\r\n\u00a0 }<\/pre>\n<p>Here&#8217;s the code for the FSR:<\/p>\n<pre>FSRValue = analogRead(analogFSR); \/\/ read the left FSR value\r\n  analogWrite(motorpin, FSRValue\/4);<\/pre>\n<p>The next step was to combine this code with the Minim library in Processing. But first, write code in Processing! Here is where several hours with Minim came in handy. I was able to hobble together enough code to be able to play and pause a song. I haven&#8217;t yet created any arrays, for a media list, but that&#8217;s next, as well as the ability to move through the array. After that I sent the output in serial DEC to Processing. I just added this little bit of code:<\/p>\n<pre>if (xpos &gt; 100){\r\n\u00a0song.play();<\/pre>\n<p>After that, I was able to use the serial output from the FSR and Photocell to trigger the song.play(); function. I suppose, I could find a audio visualization program to tweak, so that I can make a pretty picture show when a song plays, assuming I play a song.<\/p>\n<p>Next I&#8217;ll need to refine all the code, and plan out more of how I want the sensors to interact with the plants. And, I need to get some plants.<\/p>\n<p>UPDATE: Code is not working as expected. Processing is just playing a song when the sketch is run. I need to figure this out some more.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Today I got up early and fooled around in Processing&#8230;for hours. I was playing with the Minim sound library, which I&#8217;d planned to use for my Intro to Computing Media project, an mp3 player. After sitting around for so long, I could how I was getting both noticeably older in age, but also wiser about &hellip; <a href=\"https:\/\/alliwalk.com\/blog\/2009\/11\/phys-comp-icm-finals-a-nice-combination\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Using Arduino and Processing together&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[4,1,84,77,76],"tags":[160],"_links":{"self":[{"href":"https:\/\/alliwalk.com\/blog\/wp-json\/wp\/v2\/posts\/854"}],"collection":[{"href":"https:\/\/alliwalk.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/alliwalk.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/alliwalk.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/alliwalk.com\/blog\/wp-json\/wp\/v2\/comments?post=854"}],"version-history":[{"count":11,"href":"https:\/\/alliwalk.com\/blog\/wp-json\/wp\/v2\/posts\/854\/revisions"}],"predecessor-version":[{"id":882,"href":"https:\/\/alliwalk.com\/blog\/wp-json\/wp\/v2\/posts\/854\/revisions\/882"}],"wp:attachment":[{"href":"https:\/\/alliwalk.com\/blog\/wp-json\/wp\/v2\/media?parent=854"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/alliwalk.com\/blog\/wp-json\/wp\/v2\/categories?post=854"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/alliwalk.com\/blog\/wp-json\/wp\/v2\/tags?post=854"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}