{"id":5263,"date":"2022-09-07T11:03:19","date_gmt":"2022-09-07T15:03:19","guid":{"rendered":"https:\/\/courses.ideate.cmu.edu\/16-223\/f2022\/work\/?p=5263"},"modified":"2022-09-07T11:03:55","modified_gmt":"2022-09-07T15:03:55","slug":"servo-hw-alarm-clock-rebecca-kim","status":"publish","type":"post","link":"https:\/\/courses.ideate.cmu.edu\/16-223\/f2022\/work\/2022\/09\/07\/servo-hw-alarm-clock-rebecca-kim\/","title":{"rendered":"Servo HW: Alarm Clock"},"content":{"rendered":"\n<p>For this assignment, I programmed the servo so that it acts like an alarm clock. It first rings loud or vibrates. Then, it becomes snoozed and prepares to ring again. <\/p>\n\n\n\n<p>Like how I change my alarm&#8217;s setting so that it sometimes rings loud (play music) and sometimes vibrate only, I added a pseudo-random number generator to decide that for me. When &#8220;ring loud&#8221; option is chosen, the servo oscillates slowly at first and then becomes faster so that the movement is big and loud. For the vibration, I used two fast linear moves and made them repeat many times using a for loop. <\/p>\n\n\n\n<p>I also often change the snooze duration for my alarms, so I wanted the servo to decide the snooze duration for me. To achieve this, I added more pseudo-random number generators that gives me a random angle, random speed, and number of times the snoozing repeats. The snoozing is active quiet because its resetting the alarm.<\/p>\n\n\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\n# Create an object to represent a servo on the given hardware pin.\nprint(&quot;Creating servo object.&quot;)\nservo = Servo(board.GP0)\n\nprint(&quot;Starting main script: Alarm&quot;)\nwhile True:\n    # initial pause\n    time.sleep(2.0)\n\n    vibrate_or_ringloud = random.random()\n\n    if vibrate_or_ringloud &lt; 0.6:\n        # alarm slowly starting\n        print(&quot;Alarm starting&quot;)\n        ringing_move(servo, 30.0, duration=1.5)\n        ringing_move(servo, 90.0, duration=1.0)\n        ringing_move(servo, 30.0, duration=1.0)\n\n        # alarm loud ringing\n        print(&quot;Alarm ringing&quot;)\n        ringing_move(servo, 180.0, q=0, qd=400, b=0.3, duration=10.0)\n    else:\n        print(&quot;Alarm vibrating&quot;)\n        for x in range(40):\n            linear_move(servo, 0.0, 50, speed=1200)\n            linear_move(servo, 50, 0.0, speed=1200)\n\n    # slow movements to reset the alarm\n    print(&quot;Alarm snoozed&quot;)\n    snooze_repeat = random.randrange(1, 3, 1)\n    snooze_speed = random.randrange(25, 50)\n    snooze_angle = random.randrange(150, 240, 10)\n\n    for count in range(snooze_repeat):\n        print(count)\n        print(f&quot;Resetting alarm at speed {snooze_speed} at {snooze_angle} degrees&quot;)\n        linear_move(servo, 0.0, snooze_angle, speed=snooze_speed)\n        linear_move(servo, snooze_angle, 0.0, speed=snooze_speed)\n\n    # brief pause; stillness is the counterpoint\n    print(&quot;Alarm preparing to ring again&quot;)\n    time.sleep(0.5)\n<\/pre>","protected":false},"excerpt":{"rendered":"<p>For this assignment, I programmed the servo so that it acts like an alarm clock. It first rings loud or vibrates. Then, it becomes snoozed and prepares to&#8230;<\/p>\n","protected":false},"author":48,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/courses.ideate.cmu.edu\/16-223\/f2022\/work\/wp-json\/wp\/v2\/posts\/5263"}],"collection":[{"href":"https:\/\/courses.ideate.cmu.edu\/16-223\/f2022\/work\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/courses.ideate.cmu.edu\/16-223\/f2022\/work\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/16-223\/f2022\/work\/wp-json\/wp\/v2\/users\/48"}],"replies":[{"embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/16-223\/f2022\/work\/wp-json\/wp\/v2\/comments?post=5263"}],"version-history":[{"count":3,"href":"https:\/\/courses.ideate.cmu.edu\/16-223\/f2022\/work\/wp-json\/wp\/v2\/posts\/5263\/revisions"}],"predecessor-version":[{"id":5281,"href":"https:\/\/courses.ideate.cmu.edu\/16-223\/f2022\/work\/wp-json\/wp\/v2\/posts\/5263\/revisions\/5281"}],"wp:attachment":[{"href":"https:\/\/courses.ideate.cmu.edu\/16-223\/f2022\/work\/wp-json\/wp\/v2\/media?parent=5263"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/16-223\/f2022\/work\/wp-json\/wp\/v2\/categories?post=5263"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/16-223\/f2022\/work\/wp-json\/wp\/v2\/tags?post=5263"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}