{"id":5257,"date":"2022-09-07T02:06:46","date_gmt":"2022-09-07T06:06:46","guid":{"rendered":"https:\/\/courses.ideate.cmu.edu\/16-223\/f2022\/work\/?p=5257"},"modified":"2022-09-07T02:10:35","modified_gmt":"2022-09-07T06:10:35","slug":"servo-hw-melinda-chen","status":"publish","type":"post","link":"https:\/\/courses.ideate.cmu.edu\/16-223\/f2022\/work\/2022\/09\/07\/servo-hw-melinda-chen\/","title":{"rendered":"Servo HW &#8211; Melinda Chen"},"content":{"rendered":"\n<p>The purpose of my servo program was to provide a visualization for different types of numbers. In this case, numbers are divided into 3 different types, &#8216;happy&#8217; (even numbers), &#8216;sad&#8217; (odd numbers), and &#8216;special&#8217; (numbers with special meaning like pi, and e). Each type of number has a different associated choreography. Happy numbers a received with a bouncing motion, followed by a series of accelerating claps. Conversely, sad numbers get a slow sweep and a series of &#8216;crawls&#8217; back to the origin. Special numbers are explicitly spelled out by the position of the servo arm.<\/p>\n\n\n\n<p><\/p>\n\n\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\ndef happyMotor(initPause,numClaps):\n    #Bounce\n    ringing_move(servo, 90.0, duration=1.5)\n    \n    #Clap\n    for i in range(numClaps):\n        if i%2 == 0:\n            servo.write(200.0)\n        else:\n            servo.write(0.0)\n        clapPause = initPause\/(i+1)\n        time.sleep(clapPause)\n    pass\n\ndef sadMotor(numDivs,initPause):\n    #Initial Crawl\n    linear_move(servo, 0, 200.0, speed=400)\n    time.sleep(0.5)\n    prevAng = 200\n    #Sigh x amount of times\n    for i in range(numDivs):\n        ang = 200.0 - (i+1)*(200.0)\/numDivs\n        linear_move(servo, prevAng, ang, speed=400)\n        sighPause = initPause*(i+1)\n        time.sleep(sighPause)\n        prevAng = ang\n    pass\n\ndef drawNum(num,start,end):\n    for c in num:\n        digit = int(c)\n        ang = digit*(end-start)\/9\n        servo.write(ang)\n        time.sleep(0.5)\n\nwhile True:\n    servo.write(0.0)\n    specialNums = {'pi','e'}\n    num = input(&quot;Enter a number: &quot;)\n    \n    while not num.isdigit() and num not in specialNums:\n        num = input(&quot;Haha nice try, now give me a NUMBER: &quot;)\n        \n    if num == 'pi':\n        drawNum(&quot;31415926535&quot;,0,200)\n    elif num == 'e':\n        drawNum(&quot;271828&quot;,0,200)\n    else:\n        num = int(num)\n        if num%2 == 0:\n            happyMotor(1.0,15)\n        else:\n            sadMotor(3,0.8)\n<\/pre>","protected":false},"excerpt":{"rendered":"<p>The purpose of my servo program was to provide a visualization for different types of numbers. In this case, numbers are divided into 3 different types, &#8216;happy&#8217; (even&#8230;<\/p>\n","protected":false},"author":45,"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\/5257"}],"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\/45"}],"replies":[{"embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/16-223\/f2022\/work\/wp-json\/wp\/v2\/comments?post=5257"}],"version-history":[{"count":3,"href":"https:\/\/courses.ideate.cmu.edu\/16-223\/f2022\/work\/wp-json\/wp\/v2\/posts\/5257\/revisions"}],"predecessor-version":[{"id":5262,"href":"https:\/\/courses.ideate.cmu.edu\/16-223\/f2022\/work\/wp-json\/wp\/v2\/posts\/5257\/revisions\/5262"}],"wp:attachment":[{"href":"https:\/\/courses.ideate.cmu.edu\/16-223\/f2022\/work\/wp-json\/wp\/v2\/media?parent=5257"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/16-223\/f2022\/work\/wp-json\/wp\/v2\/categories?post=5257"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/16-223\/f2022\/work\/wp-json\/wp\/v2\/tags?post=5257"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}