{"id":1232,"date":"2018-11-15T21:43:00","date_gmt":"2018-11-16T02:43:00","guid":{"rendered":"http:\/\/www.joshuarosenstock.com\/teaching\/imgd3200-b18\/?p=1232"},"modified":"2018-11-15T21:44:44","modified_gmt":"2018-11-16T02:44:44","slug":"paper-nature-project-revised","status":"publish","type":"post","link":"https:\/\/www.joshuarosenstock.com\/teaching\/imgd3200-b18\/ceroberts\/paper-nature-project-revised\/","title":{"rendered":"Paper Nature Project (Revised)"},"content":{"rendered":"<p>My paper nature project consists of a wintery scene featuring a birch tree holding a tree house. Both of these objects are painted with conductive paint and attached to the MaKey MaKey. Each object is connected to a different port on the MaKey MaKey, which has been reprogrammed to produce letters instead of the original up, down, left, and right. Additionally, the MaKey MaKey has been reprogrammed to respond to capacitive touch instead of resistive touch, so the ground does not need to be used. The tree is triggered when the letter &#8220;b&#8221; is pressed and the tree house is triggered when the letter &#8220;c&#8221; is pressed. The light inside the tree house is a hacked light that I used inside a Jack-O-Lantern on Halloween. I rewired the light to use an Arduino to power it for a specific amount of time and got rid of the switch and disk battery that the light came with. The tree uses 40 LEDs taken from a digital LED strip that utilize the same Arduino to light a random LED every 150 milliseconds to simulate the sparkling of snow. The silhouette of the girl has copper tape running the back of it, which triggers the MaKey MaKey to type an &#8220;a&#8221;, which then triggers the Arduino to light the eight Neopixles that are arranged like behind the girl. The Neopixles are animated to look like footsteps to outline the path the girl has taken through the snow. In order to control all three different parts of this project I used the Serial application in Arduino as the interface between the MaKey MaKey and my Arduino Uno board. I ran into a bit of a problem here because I could not send a keyboard input without pressing the &#8220;enter&#8221; key along with whatever letter I was trying to type. To fix this I wrote a program in the Processing language that took the information from the Arduino Serial output and bypassed the need to press send, while also giving a user friendly interface to control the lights.<\/p>\n<p>Code For Capacitive Touch:<\/p>\n<pre>#include &lt;Keyboard.h&gt;\r\n\r\n#define NUM_INPUTS 18\r\n#define KEY_ENTER Keyboard.press(\r\n\r\nint keys[NUM_INPUTS] = {\r\n'a','b','c','\\n','g','m', \/\/ top of makey makey board (up, down, left, right, space, click)\r\n'h','w','e','r','t', 'y', \/\/ left side of female header\r\n'z','x','c','v','b','n' \/\/ right side of female header\r\n};\r\n\r\nint capThresholds[NUM_INPUTS] = {\r\n2, 2, 2, 2, 2, 2,\r\n2, 2, 2, 2, 2, 2,\r\n2, 2, 2, 2, 2, 2,\r\n};\r\n\r\nint pinNumbers[NUM_INPUTS] = {\r\n12, 8, 13, 15, 7, 6, \r\n5, 4, 3, 2, 1, 0, \r\n23, 22, 21, 20, 19, 18 \r\n};\r\n\r\nint outputPin = 14;\r\n\r\nboolean pressed[NUM_INPUTS];\r\n\r\nvoid setup(){\r\nKeyboard.begin();\r\nfor (int i=0; i&lt;NUM_INPUTS; i++) {\r\npressed[i] = false;\r\n}\r\n\r\npinMode(outputPin, OUTPUT);\r\ndigitalWrite(outputPin, LOW);\r\n\r\n}\r\n\r\nvoid loop() { \r\nfor (int i=0; i&lt;NUM_INPUTS; i++) { \/\/ for each pin\r\nif (readCapacitivePin(pinNumbers[i])&gt;capThresholds[i]){ \/\/ if we detect a touch on the pin\r\nif (!pressed[i]) { \/\/ and if we're not already pressed\r\nKeyboard.press(keys[i]); \/\/ send the key press\r\npressed[i] = true; \/\/ remember it was pressed\r\n}\r\n} \r\nelse { \/\/ if we don't a detect touch on the pin\r\nif (pressed[i]) { \/\/ if this key was pressed before\r\nKeyboard.release(keys[i]); \/\/ send the key release\r\npressed[i] = false; \/\/ remember we are not pressed\r\n} \r\n}\r\n}\r\n\r\nboolean anythingIsPressed = false;\r\nfor (int i=0; i&lt;NUM_INPUTS; i++) { \r\nif (pressed[i]) {\r\nanythingIsPressed = true;\r\n}\r\n}\r\n\r\nif (anythingIsPressed) {\r\ndigitalWrite(outputPin, HIGH);\r\n} \r\nelse {\r\ndigitalWrite(outputPin, LOW);\r\n}\r\n\r\n}\r\n\r\nuint8_t readCapacitivePin(int pinToMeasure) {\r\n\/\/ Variables used to translate from Arduino to AVR pin naming\r\nvolatile uint8_t* port;\r\nvolatile uint8_t* ddr;\r\nvolatile uint8_t* pin;\r\nbyte bitmask;\r\nport = portOutputRegister(digitalPinToPort(pinToMeasure));\r\nddr = portModeRegister(digitalPinToPort(pinToMeasure));\r\nbitmask = digitalPinToBitMask(pinToMeasure);\r\npin = portInputRegister(digitalPinToPort(pinToMeasure));\r\n\/\/ Discharge the pin first by setting it low and output\r\n*port &amp;= ~(bitmask);\r\n*ddr |= bitmask;\r\ndelay(1);\r\n\/\/ Make the pin an input with the internal pull-up on\r\n*ddr &amp;= ~(bitmask);\r\n*port |= bitmask;\r\n\r\nuint8_t cycles = 17;\r\nif (*pin &amp; bitmask) { \r\ncycles = 0;\r\n}\r\nelse if (*pin &amp; bitmask) { \r\ncycles = 1;\r\n}\r\nelse if (*pin &amp; bitmask) { \r\ncycles = 2;\r\n}\r\nelse if (*pin &amp; bitmask) { \r\ncycles = 3;\r\n}\r\nelse if (*pin &amp; bitmask) { \r\ncycles = 4;\r\n}\r\nelse if (*pin &amp; bitmask) { \r\ncycles = 5;\r\n}\r\nelse if (*pin &amp; bitmask) { \r\ncycles = 6;\r\n}\r\nelse if (*pin &amp; bitmask) { \r\ncycles = 7;\r\n}\r\nelse if (*pin &amp; bitmask) { \r\ncycles = 8;\r\n}\r\nelse if (*pin &amp; bitmask) { \r\ncycles = 9;\r\n}\r\nelse if (*pin &amp; bitmask) { \r\ncycles = 10;\r\n}\r\nelse if (*pin &amp; bitmask) { \r\ncycles = 11;\r\n}\r\nelse if (*pin &amp; bitmask) { \r\ncycles = 12;\r\n}\r\nelse if (*pin &amp; bitmask) { \r\ncycles = 13;\r\n}\r\nelse if (*pin &amp; bitmask) { \r\ncycles = 14;\r\n}\r\nelse if (*pin &amp; bitmask) { \r\ncycles = 15;\r\n}\r\nelse if (*pin &amp; bitmask) { \r\ncycles = 16;\r\n}\r\n\r\n*port &amp;= ~(bitmask);\r\n*ddr |= bitmask;\r\n\r\nreturn cycles;\r\n}<\/pre>\n<p>Code For Lights:<\/p>\n<pre>#include &lt;FastLED.h&gt;\r\n\r\nint incomingByte;\r\n\r\nCRGB treeleds[39];\r\nCRGB footstepleds[8];\r\n\r\nvoid setup() {\r\n\r\n  Serial.begin(9600);\r\n  pinMode (12, OUTPUT);\r\n  FastLED.addLeds&lt;WS2812B, A3&gt; (treeleds, 39);\r\n  FastLED.addLeds&lt;NEOPIXEL, A5 &gt; (footstepleds, 8);\r\n  \r\n}\r\n\r\nvoid loop() {\r\n  \r\n  if (Serial.available() &gt; 0) {\r\n    \r\n    incomingByte = Serial.read();\r\n\r\n    if (incomingByte == 'c') {\r\n\r\n      digitalWrite (12, HIGH);\r\n      delay(6000);\r\n      digitalWrite(12, LOW);\r\n      \r\n    }\r\n\r\n    if (incomingByte == 'b') {\r\n\r\n      long pixel = random(0, 40);\r\n      \r\n      for (int i = 0; i &lt;= 40; i++) {\r\n\r\n        long pixel = random(0, 40);\r\n        treeleds[pixel] = CRGB:: White;\r\n        FastLED.show();\r\n        delay(150);\r\n\r\n        treeleds[pixel] = CRGB::Black;\r\n        FastLED.show();\r\n      }\r\n    }\r\n\r\n    if (incomingByte == 'a'){\r\n\r\n     for (int i = 0; i &gt; 1; i++); {\r\n\r\n        footstepleds[0] = CRGB::Blue;\r\n        FastLED.show();\r\n        delay(500);\r\n\r\n        footstepleds[0] = CRGB::Black;\r\n        FastLED.show();\r\n        delay(500);\r\n\r\n        footstepleds[1] = CRGB::Blue;\r\n        FastLED.show();\r\n        delay(500);\r\n\r\n        footstepleds[1] = CRGB::Black;\r\n        FastLED.show();\r\n        delay(500);\r\n\r\n        footstepleds[2] = CRGB::Blue;\r\n        FastLED.show();\r\n        delay(500);\r\n\r\n        footstepleds[2] = CRGB::Black;\r\n        FastLED.show();\r\n        delay(500);\r\n\r\n        footstepleds[3] = CRGB::Blue;\r\n        FastLED.show();\r\n        delay(500);\r\n\r\n        footstepleds[3] = CRGB::Black;\r\n        FastLED.show();\r\n        delay(500);\r\n\r\n        footstepleds[4] = CRGB::Blue;\r\n        FastLED.show();\r\n        delay(500);\r\n\r\n        footstepleds[4] = CRGB::Black;\r\n        FastLED.show();\r\n        delay(500);\r\n        Serial.println(\"5\");\r\n\r\n        footstepleds[5] = CRGB::Blue;\r\n        FastLED.show();\r\n        delay(500);\r\n\r\n        footstepleds[5] = CRGB::Black;\r\n        FastLED.show();\r\n        delay(500);\r\n\r\n        footstepleds[6] = CRGB::Blue;\r\n        FastLED.show();\r\n        delay(500);\r\n\r\n        footstepleds[6] = CRGB::Black;\r\n        FastLED.show();\r\n        delay(500);\r\n\r\n        footstepleds[7] = CRGB::Blue;\r\n        FastLED.show();\r\n        delay(500);\r\n\r\n        footstepleds[7] = CRGB::Black;\r\n        FastLED.show();\r\n        delay(500);\r\n      \r\n      }\r\n    }\r\n  }\r\n}<\/pre>\n<p>Processing Code:<\/p>\n<pre>import processing.serial.*;\r\n\r\nSerial port;\r\n\r\nvoid setup() {\r\n\r\nsize(500, 500);\r\nport = new Serial(this, Serial.list()[0], 9600);\r\n\r\n}\r\n\r\nvoid draw() {\r\n\r\nfill(62, 191, 237);\r\nrect(0, 0, 600, 600);\r\n\r\n}\r\n\r\n\r\nvoid keyPressed() {\r\nif (key == 'a') {\r\n\r\nport.write('a');\r\n\r\n}\r\nif (key == 'b') {\r\n\r\nport.write('b');\r\n\r\n}\r\n\r\nif (key == 'c') {\r\n\r\nport.write('c');\r\n\r\n}\r\nelse {\r\n\r\nport.write('L');\r\n\r\n}\r\n}<\/pre>\n<p>Final Product:<\/p>\n<p><iframe loading=\"lazy\" width=\"1000\" height=\"750\" src=\"https:\/\/www.youtube.com\/embed\/NGYg0jBuXEY?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen><\/iframe><\/p>\n","protected":false},"excerpt":{"rendered":"<p>My paper nature project consists of a wintery scene featuring a birch tree holding a tree house. Both of these objects are painted with conductive paint and attached to the MaKey MaKey. Each object is connected to a different port on the MaKey MaKey, which has been reprogrammed to produce letters instead of the original&#8230; <\/p>\n<div class=\"link-more\"><a href=\"https:\/\/www.joshuarosenstock.com\/teaching\/imgd3200-b18\/ceroberts\/paper-nature-project-revised\/\">Read More<\/a><\/div>\n","protected":false},"author":105,"featured_media":1233,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"cybocfi_hide_featured_image":"","footnotes":""},"categories":[17],"tags":[],"class_list":["post-1232","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-paper-nature-revised"],"jetpack_featured_media_url":"https:\/\/www.joshuarosenstock.com\/teaching\/imgd3200-b18\/wp-content\/uploads\/sites\/8\/2018\/11\/z.jpg","_links":{"self":[{"href":"https:\/\/www.joshuarosenstock.com\/teaching\/imgd3200-b18\/wp-json\/wp\/v2\/posts\/1232","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.joshuarosenstock.com\/teaching\/imgd3200-b18\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.joshuarosenstock.com\/teaching\/imgd3200-b18\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.joshuarosenstock.com\/teaching\/imgd3200-b18\/wp-json\/wp\/v2\/users\/105"}],"replies":[{"embeddable":true,"href":"https:\/\/www.joshuarosenstock.com\/teaching\/imgd3200-b18\/wp-json\/wp\/v2\/comments?post=1232"}],"version-history":[{"count":2,"href":"https:\/\/www.joshuarosenstock.com\/teaching\/imgd3200-b18\/wp-json\/wp\/v2\/posts\/1232\/revisions"}],"predecessor-version":[{"id":1235,"href":"https:\/\/www.joshuarosenstock.com\/teaching\/imgd3200-b18\/wp-json\/wp\/v2\/posts\/1232\/revisions\/1235"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.joshuarosenstock.com\/teaching\/imgd3200-b18\/wp-json\/wp\/v2\/media\/1233"}],"wp:attachment":[{"href":"https:\/\/www.joshuarosenstock.com\/teaching\/imgd3200-b18\/wp-json\/wp\/v2\/media?parent=1232"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.joshuarosenstock.com\/teaching\/imgd3200-b18\/wp-json\/wp\/v2\/categories?post=1232"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.joshuarosenstock.com\/teaching\/imgd3200-b18\/wp-json\/wp\/v2\/tags?post=1232"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}