{"id":949,"date":"2018-04-01T21:38:20","date_gmt":"2018-04-01T21:38:20","guid":{"rendered":"https:\/\/zhutarduino.wordpress.com\/?page_id=949"},"modified":"2018-04-01T21:38:20","modified_gmt":"2018-04-01T21:38:20","slug":"processing-and-arduino-ep1-buttons","status":"publish","type":"page","link":"https:\/\/thezhut.com\/?page_id=949","title":{"rendered":"Processing and Arduino EP#1 buttons"},"content":{"rendered":"<h1>In this tutorial we will take a look at using the controlP5 library to make buttons in processing to control your Arduino..<\/h1>\n<p><iframe loading=\"lazy\" title=\"Processing and Arduino EP#1 buttons\" width=\"640\" height=\"360\" src=\"https:\/\/www.youtube.com\/embed\/NHUB6PBxI6M?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe><\/p>\n<p>&nbsp;<\/p>\n<h2>Processing Code:<\/h2>\n<p>import controlP5.*; \/\/library<br \/>\nimport processing.serial.*; \/\/library<br \/>\nSerial port; \/\/do not change<br \/>\nControlP5 cp5; \/\/create ControlP5 object<br \/>\nPFont font; \/\/do not change<\/p>\n<p>void setup() { \/\/same as arduino program<\/p>\n<p>size(300, 300); \/\/window size, (width, height)<br \/>\nport = new Serial(this, &#8220;COM3&#8221;, 9600); \/\/connected arduino port<br \/>\ncp5 = new ControlP5(this); \/\/do not change<br \/>\nfont = createFont(&#8220;Georgia Bold&#8221;, 20); \/\/font for buttons and title<\/p>\n<p>cp5.addButton(&#8220;ON&#8221;) \/\/name of button<br \/>\n.setPosition(95, 50) \/\/x and y upper left corner of button<br \/>\n.setSize(120, 70) \/\/(width, height)<br \/>\n.setFont(font) \/\/font<br \/>\n.setColorBackground(color(255, 0, 0)) \/\/background r,g,b<br \/>\n.setColorForeground(color(0, 255, 0)) \/\/mouse over color r,g,b<br \/>\n.setColorLabel(color(0, 0, 0)) \/\/text color r,g,b<br \/>\n;<\/p>\n<p>cp5.addButton(&#8220;OFF&#8221;)<br \/>\n.setPosition(95, 150)<br \/>\n.setSize(120, 70)<br \/>\n.setFont(font)<br \/>\n.setColorBackground(color(255, 0, 0))<br \/>\n.setColorForeground(color(0, 255, 0))<br \/>\n.setColorLabel(color(0, 0, 0))<br \/>\n;<br \/>\n}<\/p>\n<p>void draw() {<\/p>\n<p>background(0, 0, 0); \/\/ background color of window (r, g, b)<\/p>\n<p>}<\/p>\n<p>void ON() {<br \/>\nport.write(1);<br \/>\n}<\/p>\n<p>void OFF() {<br \/>\nport.write(2);<br \/>\n}<\/p>\n<p>&nbsp;<\/p>\n<h2>ARDUINO Code:<\/h2>\n<p>void setup() {<\/p>\n<p>pinMode(13, OUTPUT); \/\/set pin as output , red led<\/p>\n<p>Serial.begin(9600); \/\/start serial<br \/>\n}<\/p>\n<p>void loop(){<\/p>\n<p>if(Serial.available()){ \/\/id data available<\/p>\n<p>int val = Serial.read();<\/p>\n<p>if(val == 1){ \/\/if 1 received<br \/>\ndigitalWrite(13, HIGH); \/\/turn on<br \/>\n}<br \/>\nif(val == 2){ \/\/if 2 received<br \/>\ndigitalWrite(13, LOW); \/\/turn off<br \/>\n}<\/p>\n<p>}<br \/>\n}<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial we will take a look at using the controlP5 library to make buttons in processing to control your Arduino.. &nbsp; Processing Code: import controlP5.*; \/\/library import processing.serial.*; \/\/library Serial port; \/\/do not change ControlP5 cp5; \/\/create ControlP5 &hellip; <a href=\"https:\/\/thezhut.com\/?page_id=949\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"parent":947,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_monsterinsights_skip_tracking":false,"footnotes":"","_links_to":"","_links_to_target":""},"class_list":["post-949","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/thezhut.com\/index.php?rest_route=\/wp\/v2\/pages\/949","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/thezhut.com\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/thezhut.com\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/thezhut.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/thezhut.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=949"}],"version-history":[{"count":0,"href":"https:\/\/thezhut.com\/index.php?rest_route=\/wp\/v2\/pages\/949\/revisions"}],"up":[{"embeddable":true,"href":"https:\/\/thezhut.com\/index.php?rest_route=\/wp\/v2\/pages\/947"}],"wp:attachment":[{"href":"https:\/\/thezhut.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=949"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}