{"id":236,"date":"2010-11-02T01:00:19","date_gmt":"2010-11-02T01:00:19","guid":{"rendered":"http:\/\/www.mariarabinovich.com\/physcomp\/?p=236"},"modified":"2011-12-20T18:17:30","modified_gmt":"2011-12-20T18:17:30","slug":"media-controller-phase-2","status":"publish","type":"post","link":"http:\/\/www.mariarabinovich.com\/blog\/archives\/236","title":{"rendered":"Media Controller"},"content":{"rendered":"
The code finally worked at 1 am. I had tried several different ways of merging the movie manipulation code with the call and response method that was working with simple color manipulation with all of the sensors, but something was going wrong. I will try again, but the standard serial communication worked fine after a few attempts. There is a tint effect based on 3 flex sensors and one fsr controlling tint strength, a speed change based on another fsr, a video\/channel switch also from another fsr, which happens when that one reaches a value above 700. Here is the Processing code:<\/p>\n . . . . <\/p>\n The physical Part :<\/p>\n I began by making the sensors we were interested in using talk to the computer. We had ordered some sensors we wanted to play with: flex sensors, a larger force sensing resistor, accelerometers, light sensors, and a proximity sensor.<\/p>\n I wired the sensors so that we have their output ranges, and their circuit needs, and a general serial communication code. Based on the last lab, I wired them and read them as an array in processing, but this time using the call and response method to foresee any issues with delay because of the media processing.<\/p>\n They are wired in this order:<\/p>\n 0. long force sensing resistor<\/p>\n 1. flex sensing resistor<\/p>\n 2. flex sensing resistor<\/p>\n 3. accelerometer<\/p>\n 4. ambient light sensor<\/p>\n 5. infrared proximity sensor<\/p>\n digital 2. switch<\/p>\n Arduino sketch for 6 analog inputs and one switch:<\/p>\n And the processing sketch receiving 7 variables, still just using a few of the readings to move the ball from the lab, but we will transform this sensor to variable output to control our media.<\/p>\n The code finally worked at 1 am. I had tried several different ways of merging the movie manipulation code with the call and response method that was working with simple color manipulation with all of the sensors, but something was going wrong. I will try again, but the standard serial communication worked fine after a […]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[24,13,1],"tags":[],"class_list":["post-236","post","type-post","status-publish","format-standard","hentry","category-physical-computing","category-projects","category-uncategorized"],"_links":{"self":[{"href":"http:\/\/www.mariarabinovich.com\/blog\/wp-json\/wp\/v2\/posts\/236","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.mariarabinovich.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.mariarabinovich.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.mariarabinovich.com\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"http:\/\/www.mariarabinovich.com\/blog\/wp-json\/wp\/v2\/comments?post=236"}],"version-history":[{"count":18,"href":"http:\/\/www.mariarabinovich.com\/blog\/wp-json\/wp\/v2\/posts\/236\/revisions"}],"predecessor-version":[{"id":239,"href":"http:\/\/www.mariarabinovich.com\/blog\/wp-json\/wp\/v2\/posts\/236\/revisions\/239"}],"wp:attachment":[{"href":"http:\/\/www.mariarabinovich.com\/blog\/wp-json\/wp\/v2\/media?parent=236"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.mariarabinovich.com\/blog\/wp-json\/wp\/v2\/categories?post=236"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.mariarabinovich.com\/blog\/wp-json\/wp\/v2\/tags?post=236"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}
<\/a><\/p>\nimport processing.serial.*;\r\nSerial myPort;\r\nimport jmcvideo.*;\r\nimport processing.opengl.*;\r\nimport javax.media.opengl.*; \r\n\r\nint sensor1;\r\nint sensor2=0;\r\nint sensor3=0;\r\nint sensor4;\r\nint sensor5=0;\r\nint sensor6;\r\nint vidNum = 0;\r\nfloat movieRate=0;\r\nfloat movieAlpha=0;\r\n\r\nJMCMovieGL myMovie;\/\/from JMC example, load movie string\r\nint pvw, pvh;\r\nString[] vids = new String[]{\"static.mov\",\"sledding.mov\",\r\n \"slide.mov\",\"californiadreams.mov\", \"commercials.mov\",\r\n \"gummibears.mov\",\"wwf.mov\"};\r\n\r\nvoid setup() {\r\n size(800,600, OPENGL);\r\n frame.setResizable(true);\r\n background(0);\r\n\r\n myMovie = movieFromDataPath(vids[vidNum]);\r\n myMovie.loop();\r\n\r\n println(Serial.list());\/\/establish serial comm.\r\n myPort = new Serial(this, Serial.list()[0], 9600);\r\n \/\/read bytes into a buffer until you get a linefeed:\r\n myPort.bufferUntil('\\n');\r\n}\r\n\r\nvoid draw()\r\n{ \/\/background based on 3 sensor values:\r\n background(map(sensor2,0,1000,0,255),\r\n map(sensor3,250,500,0,255),\r\n map(sensor5,100,900,0,255)); \r\n\r\n \/\/draw the movie:\r\n PGraphicsOpenGL pgl = (PGraphicsOpenGL) g;\r\n\r\n GL gl = pgl.beginGL();\r\n {\r\n if (pvw != width || pvh != height)\r\n {\r\n background(0);\r\n gl.glViewport(0, 0, width, height);\r\n pvw = width;\r\n pvh = height;\r\n }\r\n \/\/change the transparency based on sensor4:\r\n movieAlpha=map(sensor4,0,900,255,1);\r\n myMovie.centerImage(gl);\r\n myMovie.alpha=(1f*movieAlpha\/255f);\r\n \/\/change the movie rate based on sensor1:\r\n movieRate=map(sensor1,0,1000,.2,2);\r\n myMovie.setRate(movieRate);\r\n }\r\n pgl.endGL();\r\n\r\n \/\/switch video when sensor 4 is on high:\r\n if(sensor4>700){\r\n vidNum = (vidNum + 1) % vids.length;\r\n myMovie.switchVideo(vids[vidNum]); }else{\r\n myMovie.loop();}\r\n} \r\n\r\n\/\/get sensor values from serial port:\r\nvoid serialEvent(Serial myPort) { \r\n\r\n String myString = myPort.readStringUntil('\\n');\r\n \/\/ if you got any bytes other than the linefeed:\r\n if (myString != null) {\r\n\r\n myString = trim(myString);\r\n\r\n \/\/ split the string at the commas\r\n \/\/ and convert the sections into integers:\r\n int sensors[] = int(split(myString, ','));\r\n\r\n \/\/ print out the values you got:\r\n for (int sensorNum = 0; sensorNum < sensors.length;\r\n sensorNum++) {\r\n print(\"Sensor \" + sensorNum + \": \" +\r\n sensors[sensorNum] + \"\\t\");\r\n }\r\n\r\n \/\/ add a linefeed after all the sensor values are printed:\r\n println();\r\n if (sensors.length > 1) {\r\n sensor1=sensors[0];\r\n sensor2=sensors[1];\r\n sensor3=sensors[2];\r\n sensor4=sensors[3];\r\n sensor5=sensors[4];\r\n sensor6=sensors[5];\r\n }\r\n }\r\n}\r\n\r\nJMCMovieGL movieFromDataPath(String filename)\r\n{\r\n return new JMCMovieGL(this, filename, RGB);\r\n}<\/pre>\nint analogOne = 0; \/\/ analog input\r\n int analogTwo = 1; \/\/ analog input\r\n int analogThree = 2;\r\n int analogFour=3;\r\n int analogFive=4;\r\n int analogSix=5;\r\n int digitalOne = 2;\r\n int sensorValue = 0; \/\/ reading from the sensor\r\n\r\n void setup() {\r\n \/\/ configure the serial connection:\r\n Serial.begin(9600);\r\n \/\/ configure the digital input:\r\n pinMode(digitalOne, INPUT);\r\n\r\n }\r\n\r\n void loop() {\r\n\r\n \/\/ read the sensor:\r\n sensorValue = analogRead(analogOne);\r\n \/\/ print the results:\r\n Serial.print(sensorValue, DEC);\r\n Serial.print(\",\");\r\n\r\n \/\/ read the sensor:\r\n sensorValue = analogRead(analogTwo);\r\n \/\/ print the results:\r\n Serial.print(sensorValue, DEC);\r\n Serial.print(\",\");\r\n\r\n \/\/ read the sensor:\r\n sensorValue = analogRead(analogThree);\r\n \/\/ print the results:\r\n Serial.print(sensorValue, DEC);\r\n Serial.print(\",\");\r\n\r\n sensorValue = analogRead(analogFour);\r\n Serial.print(sensorValue, DEC);\r\n Serial.print(\",\");\r\n\r\n sensorValue = analogRead(analogFive);\r\n Serial.print(sensorValue, DEC);\r\n Serial.print(\",\");\r\n\r\n sensorValue = analogRead(analogSix);\r\n Serial.print(sensorValue, DEC);\r\n Serial.print(\",\");\r\n\r\n \/\/sensorValue = digitalRead(digitalOne);\r\n \/\/ print the last sensor value with a println()\r\n Serial.println(sensorValue, DEC);\r\n }<\/pre>\n
\n.<\/p>\n
\n.<\/p>\n
<\/a><\/div>\n
\n.<\/p>\n
<\/a><\/div>\n
\n.<\/p>\n
<\/a><\/div>\n
<\/a><\/p>\nint analogOne = 0; \/\/ analog input\r\n int analogTwo = 1;\r\n int analogThree = 2;\r\n int analogFour=3;\r\n int analogFive=4;\r\n int analogSix=5;\r\n int digitalOne = 2; \/\/ digital input<\/pre>\n
int sensorValue = 0; \u00a0 \u00a0 \/\/ reading from the sensor<\/span><\/pre>\nboolean firstContact=false;\r\n\r\nimport processing.serial.*;\r\nSerial myPort; \r\n\r\nPFont f;\r\n\r\nfloat bgcolor;\r\nfloat fgcolorR,fgcolorG,fgcolorB;\r\nfloat xpos, ypos;\t\t \r\n\r\nvoid setup() {\r\n\r\n size(800,480);\r\n f=createFont(\"Arial\",16,true);\r\n println(Serial.list());\r\n\r\n myPort = new Serial(this, Serial.list()[0], 9600);\r\n myPort.bufferUntil('\\n');\r\n}\r\n\r\nvoid serialEvent(Serial myPort) { \r\n\r\n String myString = myPort.readStringUntil('\\n');\r\n if (myString != null) {\r\n myString = trim(myString);\r\n\r\n if(firstContact==false){\r\n if(myString.equals(\"hello\")){\r\n myPort.clear();\r\n firstContact=true;\r\n myPort.write('A');\r\n }\r\n }\r\n else{\r\n int sensors[] = int(split(myString, ','));\r\n for (int sensorNum = 0; sensorNum < sensors.length;\r\n sensorNum++) {\r\n print(\"Sensor \" + sensorNum + \": \" +\r\n sensors[sensorNum] + \"\\t\"); \r\n\r\n background(203,0,57);\r\n textFont(f);\r\n fill(0);\r\n textAlign(LEFT);\r\n text(\"sensor1: \" + sensors[0] + \" sensor2:\u00a0\"+<\/pre>\n sensors[1] +\" sensor3: \" +sensors[2]+<\/pre>\n
\" sensor4: \" +sensors[3]+ \" sensor5: \" +<\/pre>\n
sensors[4]+ \" sensor6:\"+sensors[5]+\r\n \" switch: \" +sensors[6], width\/10, height\/4);\r\n\r\n }\r\n println();<\/pre>\n
}\r\n myPort.write('A');\r\n}\r\n}\r\nvoid draw() {}<\/pre>\n
<\/a><\/pre>\n