{"id":1724,"date":"2020-10-27T18:59:07","date_gmt":"2020-10-27T22:59:07","guid":{"rendered":"https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/?p=1724"},"modified":"2020-10-27T19:01:23","modified_gmt":"2020-10-27T23:01:23","slug":"assignment-8-whos-there","status":"publish","type":"post","link":"https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/?p=1724","title":{"rendered":"Assignment 8: Who&#8217;s there?"},"content":{"rendered":"<p><strong>Problem:<\/strong><br \/>\nI go to a circuit training gym, and since it reopened after covid, we&#8217;ve had to stand in line to take our temperature before we&#8217;re allowed to be admitted into class. This designated spot is obfuscated by a bunch of equipment, and it&#8217;s not always easy for the trainer on duty to be alerted whenever someone arrives. They are also likely to be re-setting the equipment for the next class, and unable to rely on visual cues.<\/p>\n<p><strong>Solution:<\/strong><br \/>\nWhenever someone arrives at the door, the ultrasonic sensor initiates the speaker to start playing a tune to alert the trainer that someone is here. Once they take their temperature is taken and they leave that spot, the tune automatically stops because the distance sensed in the ultrasonic sensor returns back to baseline. This is less frustrating and annoying than a doorbell or buzzer, which can startle other people in the room and disrupt their pre-workout stretch.<\/p>\n<p><a href=\"https:\/\/vimeo.com\/user80133951\/review\/472812721\/a046f1c7f5\">https:\/\/vimeo.com\/user80133951\/review\/472812721\/a046f1c7f5<\/a><\/p>\n<p>Sometimes, the trainer uses a vacuum cleaner to clean the gym between classes, and can&#8217;t hear soft ambient noises. In this case, the person waiting can use a button to sound a buzzer and stop the tune playing to attract the attention of the trainer more effectively.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\">\/\/Setting up ultrasonic speaker pins\r\nconst int trigPin = 12;\r\nconst int echoPin = 13;\r\n\r\n\/\/Defines variables\r\nlong duration;\r\nint distance;\r\n\r\n\/\/Setting up speaker\r\n#include \"pitches.h\"\r\n\r\n\/\/Setting up melody:\r\nint melody[] = {\r\n  NOTE_C4, NOTE_G3, NOTE_G3, NOTE_A3, NOTE_G3, 0, NOTE_B3, NOTE_C4\r\n};\r\n\r\n\/\/ note durations: 4 = quarter note, 8 = eighth note, etc.:\r\nint noteDurations[] = {\r\n  4, 8, 8, 4, 4, 4, 4, 4, 4\r\n};\r\n\r\n\/\/buzzer interrupt\r\nstatic const int togglePin = 2;\r\nbool buzzerState = false;\r\nconst bool isInterrupt = true;\r\n\r\nvoid SwitchPressed()\r\n{\r\n  \/\/play buzzer\r\n  }\r\n\r\nvoid setup() {\r\n\/\/To read ultrasonic speaker\r\npinMode(trigPin, OUTPUT); \/\/ Sets the trigPin as an Output\r\npinMode(echoPin, INPUT); \/\/ Sets the echoPin as an Input\r\nSerial.begin(9600); \/\/ Starts the serial communication\r\npinMode(togglePin, INPUT); \/\/ Button for buzzer\r\n\r\n}\r\n\r\nvoid loop() {\r\n\r\n\/\/Reading from ultrasonic speaker\r\n\/\/ Clears the trigPin\r\ndigitalWrite(trigPin, LOW);\r\ndelayMicroseconds(2);\r\n\r\n\/\/ Sets the trigPin on HIGH state for 10 micro seconds\r\ndigitalWrite(trigPin, HIGH);\r\ndelayMicroseconds(10);\r\ndigitalWrite(trigPin, LOW);\r\n\r\n\/\/ Reads the echoPin, returns the sound wave travel time in microseconds\r\nduration = pulseIn(echoPin, HIGH);\r\n\r\n\/\/ calculate distance\r\ndistance= duration*0.034\/2;\r\n\r\n\/\/ print distance\r\nSerial.print(\"Distance: \");\r\nSerial.println(distance);\r\n\r\nif(distance&lt;100){\r\n\/\/  digitalWrite(11,HIGH);\r\n\r\n  \/\/ iterate over the notes of the melody:\r\n\r\n  for (int thisNote = 0; thisNote &lt; 8; thisNote++) {\r\n\r\n    \/\/ to calculate the note duration, take one second divided by the note type.\r\n\r\n    \/\/e.g. quarter note = 1000 \/ 4, eighth note = 1000\/8, etc.\r\n\r\n    int noteDuration = 1000 \/ noteDurations[thisNote];\r\n\r\n    tone(8, melody[thisNote], noteDuration);\r\n\r\n    \/\/ to distinguish the notes, set a minimum time between them.\r\n\r\n    \/\/ the note's duration + 30% seems to work well:\r\n\r\n    int pauseBetweenNotes = noteDuration * 1.30;\r\n\r\n    delay(pauseBetweenNotes);}\r\n\r\n}\r\n    else{\r\n\/\/  digitalWrite(11,LOW);\r\n    \/\/ stop the tone playing:\r\n    noTone(8);\r\n}\r\n}<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Problem: I go to a circuit training gym, and since it reopened after covid, we&#8217;ve had to stand in line to take our temperature before we&#8217;re allowed to be admitted into class. This designated spot is obfuscated by a bunch of equipment, and it&#8217;s not always easy for the trainer on duty to be alerted &hellip; <a href=\"https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/?p=1724\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Assignment 8: Who&#8217;s there?&#8221;<\/span><\/a><\/p>\n","protected":false},"author":26,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[18],"tags":[],"_links":{"self":[{"href":"https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/index.php?rest_route=\/wp\/v2\/posts\/1724"}],"collection":[{"href":"https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/index.php?rest_route=\/wp\/v2\/users\/26"}],"replies":[{"embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1724"}],"version-history":[{"count":5,"href":"https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/index.php?rest_route=\/wp\/v2\/posts\/1724\/revisions"}],"predecessor-version":[{"id":1740,"href":"https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/index.php?rest_route=\/wp\/v2\/posts\/1724\/revisions\/1740"}],"wp:attachment":[{"href":"https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1724"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1724"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1724"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}