{"id":2300,"date":"2022-02-21T21:28:44","date_gmt":"2022-02-22T02:28:44","guid":{"rendered":"https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/?p=2300"},"modified":"2022-02-21T21:41:21","modified_gmt":"2022-02-22T02:41:21","slug":"assignment-6-james-kyle","status":"publish","type":"post","link":"https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/?p=2300","title":{"rendered":"Assignment 6 &#8211; James Kyle"},"content":{"rendered":"<p><span style=\"text-decoration: underline\"><strong>Daylight Level Indicator:<\/strong><\/span><\/p>\n<p>For this assignment, I have made a theoretical daylight level sensor. The inspiration for this comes from my lab being in the basement of Ansys. We have no windows down there so I can easily get sucked into work and stay there for hours without realizing what time of day it is and\/or whether it is time to pack up and call it a day. This daylight level indicator is meant to solve this problem by sensing the amount of daylight coming from outside and physically turning a dial to show the time of day. Theoretically, this dial would take the shape of a circle with night and day images on either side. The servo would turn to the appropriate position to indicate how close the sun is to setting or rising depending on the level of light outside and the time of day.<\/p>\n<div style=\"width: 840px;\" class=\"wp-video\"><!--[if lt IE 9]><script>document.createElement('video');<\/script><![endif]-->\n<video class=\"wp-video-shortcode\" id=\"video-2300-1\" width=\"840\" height=\"1493\" preload=\"metadata\" controls=\"controls\"><source type=\"video\/mp4\" src=\"https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/wp-content\/uploads\/2022\/02\/IMG_7377.mp4?_=1\" \/><a href=\"https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/wp-content\/uploads\/2022\/02\/IMG_7377.mp4\">https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/wp-content\/uploads\/2022\/02\/IMG_7377.mp4<\/a><\/video><\/div>\n<p><img loading=\"lazy\" class=\"alignnone  wp-image-2304\" src=\"https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/wp-content\/uploads\/2022\/02\/DaylightSensor_Fritzing-300x241.jpg\" alt=\"\" width=\"748\" height=\"601\" srcset=\"https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/wp-content\/uploads\/2022\/02\/DaylightSensor_Fritzing-300x241.jpg 300w, https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/wp-content\/uploads\/2022\/02\/DaylightSensor_Fritzing-1024x823.jpg 1024w, https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/wp-content\/uploads\/2022\/02\/DaylightSensor_Fritzing-768x617.jpg 768w, https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/wp-content\/uploads\/2022\/02\/DaylightSensor_Fritzing-1536x1234.jpg 1536w, https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/wp-content\/uploads\/2022\/02\/DaylightSensor_Fritzing-1200x964.jpg 1200w, https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/wp-content\/uploads\/2022\/02\/DaylightSensor_Fritzing.jpg 1755w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\">#include &lt;Servo.h&gt;\r\n\r\n\r\nint hours = 0;\r\n\r\nconst int measurementNumber = 20;\r\nint measurementCount = 0;\r\nint lightMeasurements[measurementNumber];\r\nconst int lightLevel = A0; \/\/Light level pin (photoresistor pin)\r\n\r\nint lightBottomBound = 0;\r\nint lightTopBound = 0;\r\n\r\n\r\nServo myServo;\r\nint SERVOPIN = 9;\r\n\r\n\r\n\r\nvoid setup() {\r\n\r\n  pinMode(lightLevel, INPUT);\r\n\r\n  myServo.attach(9);\r\n\r\n}\r\n\r\nvoid loop() {\r\n\r\n  \/\/Update measurement counter\r\n  if (measurementCount &lt; measurementNumber) {\r\n    measurementCount += 1;\r\n  } else {\r\n    measurementCount = 0;\r\n  }\r\n\r\n\r\n  \/\/Update light level average\r\n  int lightLevelSum = 0;\r\n  for (int i = 1; i &lt; measurementNumber; i++) {\r\n    lightLevelSum += lightMeasurements[i];\r\n  }\r\n\r\n  int lightLevelAverage = lightLevelSum \/ measurementNumber;\r\n\r\n\r\n\r\n  \/\/Update light level measurements\r\n  int currentLightLevel = analogRead(lightLevel);\r\n  lightMeasurements[measurementCount] = currentLightLevel;\r\n\r\n\r\n\r\n\r\n  \/\/Change bounds if light level is outside of bounds\r\n  if (lightLevelAverage &lt; lightBottomBound) {\r\n    lightBottomBound = lightLevelAverage;\r\n  }\r\n\r\n  if (lightLevelAverage &gt; lightTopBound) {\r\n    lightTopBound = lightLevelAverage;\r\n  }\r\n\r\n\r\n  \/\/Write to servo\r\n  int servoAngle = map(lightLevelAverage, lightBottomBound, lightTopBound, 0, 180);\r\n  myServo.write(servoAngle);\r\n\r\n\r\n  delay(1000);\r\n\r\n}<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Daylight Level Indicator: For this assignment, I have made a theoretical daylight level sensor. The inspiration for this comes from my lab being in the basement of Ansys. We have no windows down there so I can easily get sucked into work and stay there for hours without realizing what time of day it is &hellip; <a href=\"https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/?p=2300\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Assignment 6 &#8211; James Kyle&#8221;<\/span><\/a><\/p>\n","protected":false},"author":29,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[15],"tags":[],"_links":{"self":[{"href":"https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/index.php?rest_route=\/wp\/v2\/posts\/2300"}],"collection":[{"href":"https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/index.php?rest_route=\/wp\/v2\/users\/29"}],"replies":[{"embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2300"}],"version-history":[{"count":3,"href":"https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/index.php?rest_route=\/wp\/v2\/posts\/2300\/revisions"}],"predecessor-version":[{"id":2305,"href":"https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/index.php?rest_route=\/wp\/v2\/posts\/2300\/revisions\/2305"}],"wp:attachment":[{"href":"https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2300"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2300"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2300"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}