{"id":12717,"date":"2021-04-03T12:42:40","date_gmt":"2021-04-03T16:42:40","guid":{"rendered":"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/?p=12717"},"modified":"2021-04-09T00:39:01","modified_gmt":"2021-04-09T04:39:01","slug":"screentime-watchman","status":"publish","type":"post","link":"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/screentime-watchman\/","title":{"rendered":"Screentime Watchman"},"content":{"rendered":"<h6 style=\"text-align: left\">By: Vishnu Raghavan<\/h6>\n<p>&nbsp;<\/p>\n<p style=\"text-align: center\">After a time limit is exceeded, two Servo motors push your computer screen closed, signaling time for a break.<\/p>\n<p><img loading=\"lazy\" class=\"alignleft wp-image-12720\" src=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/featured_closed-scaled.jpg\" alt=\"\" width=\"398\" height=\"299\" srcset=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/featured_closed-scaled.jpg 2560w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/featured_closed-300x225.jpg 300w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/featured_closed-1024x768.jpg 1024w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/featured_closed-768x576.jpg 768w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/featured_closed-1536x1152.jpg 1536w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/featured_closed-2048x1536.jpg 2048w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/featured_closed-973x730.jpg 973w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/featured_closed-508x381.jpg 508w\" sizes=\"(max-width: 398px) 100vw, 398px\" \/><\/p>\n<p><strong><img loading=\"lazy\" class=\"wp-image-12721 alignleft\" style=\"text-align: center\" src=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/featured_open-300x225.jpg\" alt=\"\" width=\"403\" height=\"302\" srcset=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/featured_open-300x225.jpg 300w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/featured_open-1024x768.jpg 1024w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/featured_open-768x576.jpg 768w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/featured_open-1536x1152.jpg 1536w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/featured_open-2048x1536.jpg 2048w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/featured_open-973x730.jpg 973w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/featured_open-508x381.jpg 508w\" sizes=\"(max-width: 403px) 100vw, 403px\" \/><\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Demo:<\/strong><\/p>\n<div style=\"width: 620px;\" class=\"wp-video\"><!--[if lt IE 9]><script>document.createElement('video');<\/script><![endif]-->\n<video class=\"wp-video-shortcode\" id=\"video-12717-1\" width=\"620\" height=\"349\" preload=\"metadata\" controls=\"controls\"><source type=\"video\/mp4\" src=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/demo_vid_tmp-2.mp4?_=1\" \/><a href=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/demo_vid_tmp-2.mp4\">https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/demo_vid_tmp-2.mp4<\/a><\/video><\/div>\n<p>&nbsp;<\/p>\n<p><strong>Ideation:<\/strong><\/p>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-12923\" src=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/IMG_3673-225x300.jpg\" alt=\"\" width=\"397\" height=\"530\" srcset=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/IMG_3673-225x300.jpg 225w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/IMG_3673-768x1024.jpg 768w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/IMG_3673-1152x1536.jpg 1152w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/IMG_3673-1536x2048.jpg 1536w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/IMG_3673-973x1297.jpg 973w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/IMG_3673-508x677.jpg 508w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/IMG_3673-scaled.jpg 1920w\" sizes=\"(max-width: 397px) 100vw, 397px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><strong>Photo for Scale:<\/strong><\/p>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-12726\" src=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/scale-300x225.jpg\" alt=\"\" width=\"400\" height=\"300\" srcset=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/scale-300x225.jpg 300w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/scale-1024x768.jpg 1024w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/scale-768x576.jpg 768w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/scale-1536x1152.jpg 1536w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/scale-2048x1536.jpg 2048w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/scale-973x730.jpg 973w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/scale-508x381.jpg 508w\" sizes=\"(max-width: 400px) 100vw, 400px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><strong>Servo Motor:<\/strong><\/p>\n<div id=\"attachment_12727\" style=\"width: 483px\" class=\"wp-caption alignnone\"><img aria-describedby=\"caption-attachment-12727\" loading=\"lazy\" class=\"wp-image-12727\" src=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/featured_servo-768x1024.jpg\" alt=\"\" width=\"473\" height=\"631\" srcset=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/featured_servo-768x1024.jpg 768w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/featured_servo-225x300.jpg 225w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/featured_servo-1152x1536.jpg 1152w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/featured_servo-1536x2048.jpg 1536w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/featured_servo-973x1297.jpg 973w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/featured_servo-508x677.jpg 508w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/featured_servo-scaled.jpg 1920w\" sizes=\"(max-width: 473px) 100vw, 473px\" \/><p id=\"caption-attachment-12727\" class=\"wp-caption-text\">Servo motor (1\/2) that pushes the computer screen down when the screentime limit is exceeded<\/p><\/div>\n<p>&nbsp;<\/p>\n<p><strong>Arduino Control<\/strong> <strong>Center:<\/strong><\/p>\n<div id=\"attachment_12728\" style=\"width: 630px\" class=\"wp-caption alignnone\"><img aria-describedby=\"caption-attachment-12728\" loading=\"lazy\" class=\"wp-image-12728 size-large\" src=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/featured_brain-scaled-e1617477934649-1024x768.jpg\" alt=\"\" width=\"620\" height=\"465\" srcset=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/featured_brain-scaled-e1617477934649-1024x768.jpg 1024w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/featured_brain-scaled-e1617477934649-300x225.jpg 300w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/featured_brain-scaled-e1617477934649-768x576.jpg 768w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/featured_brain-scaled-e1617477934649-1536x1152.jpg 1536w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/featured_brain-scaled-e1617477934649-2048x1536.jpg 2048w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/featured_brain-scaled-e1617477934649-973x730.jpg 973w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/featured_brain-scaled-e1617477934649-508x381.jpg 508w\" sizes=\"(max-width: 620px) 100vw, 620px\" \/><p id=\"caption-attachment-12728\" class=\"wp-caption-text\">Main &#8220;control center&#8221; of device. Contains Arduino, as well as breadboard with accelerometer (for sensing &#8220;open&#8221; vs &#8220;closed&#8221; orientation of screen) and potentiometer (for adjusting screentime limit).<\/p><\/div>\n<p>&nbsp;<\/p>\n<p><strong>Decision Points:<\/strong><\/p>\n<ol>\n<li>Decided to use accelerometer instead of pressure sensor:<\/li>\n<\/ol>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-12732 \" src=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/accelerometer_decision-scaled.jpg\" alt=\"\" width=\"832\" height=\"624\" srcset=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/accelerometer_decision-scaled.jpg 2560w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/accelerometer_decision-300x225.jpg 300w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/accelerometer_decision-1024x768.jpg 1024w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/accelerometer_decision-768x576.jpg 768w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/accelerometer_decision-1536x1152.jpg 1536w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/accelerometer_decision-2048x1536.jpg 2048w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/accelerometer_decision-973x730.jpg 973w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/accelerometer_decision-508x381.jpg 508w\" sizes=\"(max-width: 832px) 100vw, 832px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: left\">2. Decided to create a wood-based platform\/environment for project, along with a wood box to enclose Arduino:<\/p>\n<p>&nbsp;<\/p>\n<div id=\"attachment_12731\" style=\"width: 383px\" class=\"wp-caption alignleft\"><img aria-describedby=\"caption-attachment-12731\" loading=\"lazy\" class=\"wp-image-12731\" src=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/mockup_decision-300x225.jpg\" alt=\"\" width=\"373\" height=\"280\" srcset=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/mockup_decision-300x225.jpg 300w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/mockup_decision-1024x768.jpg 1024w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/mockup_decision-768x576.jpg 768w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/mockup_decision-1536x1152.jpg 1536w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/mockup_decision-2048x1536.jpg 2048w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/mockup_decision-973x730.jpg 973w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/mockup_decision-508x381.jpg 508w\" sizes=\"(max-width: 373px) 100vw, 373px\" \/><p id=\"caption-attachment-12731\" class=\"wp-caption-text\">I decided to make a platform containing all the parts of the project; after building a mockup, I realized I could apply my woodworking skills to craft an aesthetically-pleasing base for the final project.<\/p><\/div>\n<div id=\"attachment_12730\" style=\"width: 250px\" class=\"wp-caption alignleft\"><img aria-describedby=\"caption-attachment-12730\" loading=\"lazy\" class=\"wp-image-12730\" src=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/woodshop_decision-225x300.jpg\" alt=\"\" width=\"240\" height=\"320\" srcset=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/woodshop_decision-225x300.jpg 225w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/woodshop_decision-768x1024.jpg 768w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/woodshop_decision-1152x1536.jpg 1152w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/woodshop_decision-1536x2048.jpg 1536w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/woodshop_decision-973x1297.jpg 973w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/woodshop_decision-508x677.jpg 508w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/woodshop_decision-scaled.jpg 1920w\" sizes=\"(max-width: 240px) 100vw, 240px\" \/><p id=\"caption-attachment-12730\" class=\"wp-caption-text\">To keep the project aesthetically clean, I did not want the Arduino and other wiring to be visible. I eventually decided to make a sliding lid, which would allow me to reach in and fiddle with the electronics if need be.<\/p><\/div>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Discussion:<\/strong><\/p>\n<p>While I was very satisfied and thankful\u00a0 I was able to get the meat of my project working, there were certain features or glitches which I believe could be improved or fixed for a future iteration. Based on a classmate&#8217;s feedback, one improvement concerns how the Arduino is placed: &#8220;<span style=\"font-weight: 400\">The box seems a little bulky to attach on the back of your computer, so maybe there\u2019s a nicer way to hold the Arduino.&#8221; In the original project, I enclosed the arduino inside a wooden box with a sliding top, for ease of access. I then mounted the box on the back of the computer screen, taping it to hold it together (avoiding glue, as that would damage the computer case). However, based on the feedback, I can actually move the box off of the computer. To accomplish this, I will need to allocated a larger plaftform to accomodate the box, its wiring, and the servo motors, and the speaker pad. Additionally, a major reason I mounted the box on the computer was because the Arduino&#8217;s upload cable had to connect to the Mac&#8217;s USB port. In the future, I will invest in a special adaptor or extender that will allow me to connect to the computer without keeping the Arduino in close proximity.<\/span><\/p>\n<p>Although I did attempt to add an aesthetic tone to the project, there were certain aspects about it which were still &#8220;exposed&#8221;. Most notably, much of the wiring I used was visible, especially on the breadboard which contained the speaker. As one classmate recommended, &#8220;<span style=\"font-weight: 400\">Possibly a next step could be a phone mount onto your screen. That way you wouldn\u2019t need any extra cables, and you could use a graphical user interface to set the screentime.&#8221; Not only would this clean up any exposed (and confusing) wiring I may have, it will add an extra layer of robust complexity to my project. Not only would I be challenged in finding a way to digitize my interface, I would also need to make the design user-friendly. I would focus on optimizing my project on a hardware, software, and user-centric level.<\/span><\/p>\n<p>In spite of the end result, the workflow was bumpy. During the process, I was nervous that my accelerometer would not be very sensitive to the change in position to the computer screen, and therefore not be able to send a meaningful signal to the servo motors. In fact this was initially a problem, as my accelerometer was not outputting logical values based on position. I soon realized that, since I was reusing an accelerometer from the previous project, the solder used must have fried the board. After switching to a fresh piece, it worked fine.<\/p>\n<p>One major source of annoyance, and a general failure of my project, was the speaker, which would ideally beep when my screentime limit was almost exceeded. In this way, the speaker would act as a &#8220;warning&#8221;, allowing me to save any work before the motors would slam the computer shut. I played around with the &#8220;debouncing&#8221; framework in the early stages (the speaker was originally button-controlled) but eventually sought to employ a simpler &#8220;delay&#8221; framework. I did have to keep track of the current and previous states, but I would get mixed results. Sometimes, the speaker would blare correctly, but after a few iterations of opening and closing, would stop emitting completely. Given the time crunch, I decided to move on from this problem, in order to devote more time to the aesthetic aspects of the project.<\/p>\n<p>Another idea that I had, but which never came to fruition, was to create an LCD display that would output the total amount of screentime, as well as the time left. However, given both the time crunch, as well as the revelation that I could not maneuver a large amount of wiring at that point in the project, I ended up scrapping the idea. Nonetheless, this is an idea that would be good for a future iteration.<\/p>\n<p>Overall, I was proud of how my project turned out. I am especially proud of how I incorporated my woodworking experience into the project, given that I had taken the woodworking mini just this semester. I was relieved to be able to get the servo motors working reliably, along with the sliding box top I had built in the woodshop. Looking ahead, I would like to try to digitize much of the controls, perhaps through a touch-screen GUI and some Wifi-enabled connection. This will challenge me to broaden my expertise beyond simple electronics, to the world of cloud software and computing.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Technical information:<\/strong><\/p>\n<p>Block diagram\/Schematic:<\/p>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-12939 size-large\" src=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/screentime_watchman-955x1024.jpg\" alt=\"\" width=\"620\" height=\"665\" srcset=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/screentime_watchman-955x1024.jpg 955w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/screentime_watchman-280x300.jpg 280w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/screentime_watchman-768x823.jpg 768w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/screentime_watchman-973x1043.jpg 973w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/screentime_watchman-508x545.jpg 508w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/04\/screentime_watchman.jpg 1251w\" sizes=\"(max-width: 620px) 100vw, 620px\" \/><\/p>\n<p>Code:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"c\">\/*60-223 Project 2: Screentime Watchman\r\n * Vishnu Raghavan (vishnur)\r\n * April 8th, 2021\r\n * \r\n * Description: This code measures the orientation of the laptop screen via an accelerometer.\r\n * Once the laptop reaches 90 degrees upright, a timer starts (determined by the current potentiometer setting). \r\n * When the timer nears a certain limit, the speaker goes off, and soon afterwards, \r\n * the Servo motors swing by a certain (predetermined) angle.\r\n * \r\n * Pin mapping:\r\n * \r\n * Arduino Pin | Type | Description\r\n * ------------|------|------------\r\n * 5            output  Right servo\r\n * 7            output  Left servo\r\n * 8            output  8-ohm speaker\r\n * A1           input   X-input to accelerometer\r\n * A2           input   Y-input to accelerometer\r\n * A3           input   Z-input to accelerometer\r\n * A5           input   Potentiometer to control screentime\r\n * \r\n * Code bits: \r\n * -Accelerometer code taken partially from maker cards website\r\n * -Servo setup taken from Servo example in class\r\n *\/\r\n\r\n\r\n#include &lt;Servo.h&gt;\r\n\r\nconst int accelXPin = A1; \/\/ Analog input pin for X movement\r\nconst int accelYPin = A2; \/\/ Analog input pin for Y movement\r\nconst int accelZPin = A3; \/\/ Analog input pin for Z movement\r\n\r\nconst int SPEAKERPIN = 8;\r\nconst int POTPIN = A5;\r\n\r\nServo motor1;\r\nServo motor2;\r\n\r\nconst int MOTORPIN1 = 5;\r\nconst int MOTORPIN2 = 7;\r\n\r\n\/\/Servos in \"down\" position \r\nconst int INIT_ANGLE1 = 65;\r\nconst int INIT_ANGLE2 = 160;\r\n\r\n\/\/Servos in \"up\" position\r\nconst int FINAL_ANGLE1 = 160;\r\nconst int FINAL_ANGLE2 = 65;\r\n\r\n\r\n\/\/ Variables to keep track of the current positions\r\nint accelXPos = 0;\r\nint accelYPos = 0;\r\nint accelZPos = 0;\r\n\r\n\/\/Timer, and flags to keep track of current and prev state of screen\r\nint timer = 0;\r\nbool prevUp = LOW;\r\nbool currUp = LOW;\r\n\r\nunsigned int screenTime;\r\n\r\n\r\nvoid setup() {\r\n\r\n  motor1.attach(MOTORPIN1);\r\n  motor2.attach(MOTORPIN2);\r\n  \r\n  pinMode(accelXPin, INPUT);\r\n  pinMode(accelYPin, INPUT);\r\n  pinMode(accelZPin, INPUT);\r\n\r\n  pinMode(SPEAKERPIN, OUTPUT);\r\n  pinMode(POTPIN, INPUT);\r\n\r\n  motor1.write(INIT_ANGLE1);\r\n  motor2.write(INIT_ANGLE2);\r\n\r\n  Serial.begin(9600);\r\n\r\n  \r\n}\r\n\r\nvoid loop() {\r\n  \/\/Get accelerometer orientation (specifically, height)\r\n  accelZPos = analogRead(accelZPin);\r\n\r\n  int screenTimeTmp = analogRead(POTPIN);\r\n  screenTime = map(screenTimeTmp, 0, 1023, 3000, 8000); \/\/Better range for screentime\r\n  delay(1000);\r\n\r\n  \/\/Screen down\r\n  if (390 &lt;= accelZPos and accelZPos &lt;= 405) {\r\n    motor1.write(INIT_ANGLE1);\r\n    motor2.write(INIT_ANGLE2);\r\n    timer = 0; \/\/Timer off\r\n    currUp = LOW;\r\n    \r\n    noTone(SPEAKERPIN);\r\n  }\r\n\r\n\r\n  \/\/Screen just flipped up\r\n  if (accelZPos &gt;= 320 and accelZPos &lt;= 340 and prevUp == LOW) {\r\n    timer = millis();\r\n    currUp = HIGH;\r\n  }\r\n\r\n  \/\/If screen up for 4 seconds, warning speaker for 2s\r\n  if (accelZPos &gt;= 320 and accelZPos &lt;= 340 and \r\n      prevUp == HIGH and millis() - timer &gt;= (screenTime - 3000) and millis() - timer &lt;= (screenTime - 1000))\r\n  {\r\n    tone(SPEAKERPIN, 500);  \r\n  }\r\n\r\n  \/\/After 6 seconds total (2s after warning), flip screen down\r\n  if (accelZPos &gt;= 320 and accelZPos &lt;= 340 and prevUp == HIGH and millis() - timer &gt;= screenTime) {\r\n    motor1.write(FINAL_ANGLE1);\r\n    motor2.write(FINAL_ANGLE2);\r\n\r\n\r\n    currUp = LOW;\r\n    timer = millis(); \/\/Reset timer\r\n    noTone(SPEAKERPIN);\r\n  }\r\n\r\n  \/\/Update prev state of screen\r\n  prevUp = currUp;\r\n  \r\n  \r\n\r\n}<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>By: Vishnu Raghavan &nbsp; After a time limit is exceeded, two Servo motors push your computer screen closed, signaling time for a break. &nbsp; &nbsp; &nbsp; Demo: &nbsp;&#8230;<\/p>\n","protected":false},"author":182,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"image","meta":[],"categories":[89],"tags":[],"_links":{"self":[{"href":"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-json\/wp\/v2\/posts\/12717"}],"collection":[{"href":"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-json\/wp\/v2\/users\/182"}],"replies":[{"embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-json\/wp\/v2\/comments?post=12717"}],"version-history":[{"count":29,"href":"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-json\/wp\/v2\/posts\/12717\/revisions"}],"predecessor-version":[{"id":12954,"href":"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-json\/wp\/v2\/posts\/12717\/revisions\/12954"}],"wp:attachment":[{"href":"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-json\/wp\/v2\/media?parent=12717"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-json\/wp\/v2\/categories?post=12717"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-json\/wp\/v2\/tags?post=12717"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}