{"id":177,"date":"2010-10-29T15:08:59","date_gmt":"2010-10-29T15:08:59","guid":{"rendered":"http:\/\/www.mariarabinovich.com\/physcomp\/?p=177"},"modified":"2011-12-20T18:15:11","modified_gmt":"2011-12-20T18:15:11","slug":"stupid-media-controller-trick","status":"publish","type":"post","link":"http:\/\/www.mariarabinovich.com\/blog\/archives\/177","title":{"rendered":"Media Controller tech"},"content":{"rendered":"

We decided to make a squishy soft video\/audio controller.<\/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

\"\"<\/a><\/p>\n

Arduino sketch for 6 analog inputs and one switch:<\/p>\n

int 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>\n
void setup() {<\/div>\n
Serial.begin(9600);<\/div>\n
pinMode(digitalOne, INPUT);<\/div>\n
establishContact();<\/div>\n
}<\/div>\n
void loop() { if(Serial.available()>0){ int inByte=Serial.read(); sensorValue = analogRead(analogOne); Serial.print(sensorValue, DEC); Serial.print(“,”); sensorValue = analogRead(analogTwo); Serial.print(sensorValue, DEC); Serial.print(“,”); sensorValue = analogRead(analogThree); Serial.print(sensorValue, DEC); Serial.print(“,”); sensorValue = analogRead(analogFour); Serial.print(sensorValue, DEC); Serial.print(“,”); sensorValue = analogRead(analogFive); Serial.print(sensorValue, DEC); Serial.print(“,”); sensorValue = analogRead(analogSix); Serial.print(sensorValue, DEC); Serial.print(“,”); sensorValue = digitalRead(digitalOne); \/\/ print the last sensor value with a println() Serial.println(sensorValue, DEC); } } void establishContact(){ while(Serial.available()<=0){ Serial.println(“hello”); delay(300); } }<\/div>\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

boolean 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","protected":false},"excerpt":{"rendered":"

We decided to make a squishy soft video\/audio controller. 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. I wired the sensors so that we […]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[24,1],"tags":[],"class_list":["post-177","post","type-post","status-publish","format-standard","hentry","category-physical-computing","category-uncategorized"],"_links":{"self":[{"href":"http:\/\/www.mariarabinovich.com\/blog\/wp-json\/wp\/v2\/posts\/177","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=177"}],"version-history":[{"count":22,"href":"http:\/\/www.mariarabinovich.com\/blog\/wp-json\/wp\/v2\/posts\/177\/revisions"}],"predecessor-version":[{"id":219,"href":"http:\/\/www.mariarabinovich.com\/blog\/wp-json\/wp\/v2\/posts\/177\/revisions\/219"}],"wp:attachment":[{"href":"http:\/\/www.mariarabinovich.com\/blog\/wp-json\/wp\/v2\/media?parent=177"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.mariarabinovich.com\/blog\/wp-json\/wp\/v2\/categories?post=177"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.mariarabinovich.com\/blog\/wp-json\/wp\/v2\/tags?post=177"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}