{"id":2876,"date":"2014-10-01T17:54:20","date_gmt":"2014-10-01T21:54:20","guid":{"rendered":"https:\/\/itp.nyu.edu\/physcomp\/?page_id=2876"},"modified":"2020-07-29T06:25:50","modified_gmt":"2020-07-29T10:25:50","slug":"class-oct-1-afternoon","status":"publish","type":"page","link":"https:\/\/itp.nyu.edu\/physcomp\/itp\/sections\/class-oct-1-afternoon\/","title":{"rendered":"Class Oct 1 Afternoon"},"content":{"rendered":"<pre class=\"brush: arduino; light: true; title: ; notranslate\" title=\"\">\r\nimport processing.serial.*;\r\n\r\nSerial myPort;\r\nint xPos, yPos;\r\nint message = 'x';\r\n\r\nvoid setup() {\r\n  size(640, 480);\r\n  println(Serial.list());\r\n  String portName = &quot;\/dev\/tty.usbmodem1411&quot;;\r\n  myPort = new Serial(this, portName, 9600);\r\n  myPort.bufferUntil('\\n');\r\n}\r\n\r\nvoid draw() {\r\n  background(#2255DD);\r\n  ellipse(xPos, yPos, 30, 30);\r\n}\r\n\r\nvoid serialEvent(Serial myPort) {\r\n  String inputString = myPort.readString();\r\n  inputString = trim(inputString);\r\n  String&#x5B;] pieces = split(inputString, &quot;,&quot;);\r\n  int&#x5B;] values = int(pieces);\r\n  if (values.length &gt; 1) {\r\n    xPos = values&#x5B;0];\r\n    yPos = values&#x5B;1];\r\n  }\r\n  myPort.write(message);\r\n}\r\n\r\nvoid keyPressed() {\r\n  message = key;\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>import processing.serial.*; Serial myPort; int xPos, yPos; int message = &#8216;x&#8217;; void setup() { size(640, 480); println(Serial.list()); String portName = &quot;\/dev\/tty.usbmodem1411&quot;; myPort = new Serial(this, portName, 9600); myPort.bufferUntil(&#8216;\\n&#8217;); } void draw() { background(#2255DD); ellipse(xPos, yPos, 30, 30); } void serialEvent(Serial myPort) { String inputString = myPort.readString(); inputString = trim(inputString); String&#x5B;] pieces = split(inputString, &quot;,&quot;); int&#x5B;] &hellip; <a href=\"https:\/\/itp.nyu.edu\/physcomp\/itp\/sections\/class-oct-1-afternoon\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Class Oct 1 Afternoon&#8221;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"parent":9,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"categories":[58],"tags":[],"class_list":["post-2876","page","type-page","status-publish","hentry","category-retired"],"_links":{"self":[{"href":"https:\/\/itp.nyu.edu\/physcomp\/wp-json\/wp\/v2\/pages\/2876"}],"collection":[{"href":"https:\/\/itp.nyu.edu\/physcomp\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/itp.nyu.edu\/physcomp\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/itp.nyu.edu\/physcomp\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/itp.nyu.edu\/physcomp\/wp-json\/wp\/v2\/comments?post=2876"}],"version-history":[{"count":1,"href":"https:\/\/itp.nyu.edu\/physcomp\/wp-json\/wp\/v2\/pages\/2876\/revisions"}],"predecessor-version":[{"id":2877,"href":"https:\/\/itp.nyu.edu\/physcomp\/wp-json\/wp\/v2\/pages\/2876\/revisions\/2877"}],"up":[{"embeddable":true,"href":"https:\/\/itp.nyu.edu\/physcomp\/wp-json\/wp\/v2\/pages\/9"}],"wp:attachment":[{"href":"https:\/\/itp.nyu.edu\/physcomp\/wp-json\/wp\/v2\/media?parent=2876"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itp.nyu.edu\/physcomp\/wp-json\/wp\/v2\/categories?post=2876"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itp.nyu.edu\/physcomp\/wp-json\/wp\/v2\/tags?post=2876"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}