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, ‘happy’ (even numbers), ‘sad’ (odd numbers), and ‘special’ (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 ‘crawls’ back to the origin. Special numbers are explicitly spelled out by the position of the servo arm.
def happyMotor(initPause,numClaps): #Bounce ringing_move(servo, 90.0, duration=1.5) #Clap for i in range(numClaps): if i%2 == 0: servo.write(200.0) else: servo.write(0.0) clapPause = initPause/(i+1) time.sleep(clapPause) pass def sadMotor(numDivs,initPause): #Initial Crawl linear_move(servo, 0, 200.0, speed=400) time.sleep(0.5) prevAng = 200 #Sigh x amount of times for i in range(numDivs): ang = 200.0 - (i+1)*(200.0)/numDivs linear_move(servo, prevAng, ang, speed=400) sighPause = initPause*(i+1) time.sleep(sighPause) prevAng = ang pass def drawNum(num,start,end): for c in num: digit = int(c) ang = digit*(end-start)/9 servo.write(ang) time.sleep(0.5) while True: servo.write(0.0) specialNums = {'pi','e'} num = input("Enter a number: ") while not num.isdigit() and num not in specialNums: num = input("Haha nice try, now give me a NUMBER: ") if num == 'pi': drawNum("31415926535",0,200) elif num == 'e': drawNum("271828",0,200) else: num = int(num) if num%2 == 0: happyMotor(1.0,15) else: sadMotor(3,0.8)
Leave a Reply
You must be logged in to post a comment.