Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- angle = 0
- quit = False
- def update_stepper():
- global angle #reads the global angle variable
- while True:
- if cur_angle < angle:
- step_right() ##function to step the motor once in the right direction
- elif(cur_angle > angle):
- step_left() ##function to step the motor once in the right direction
- else:
- time.sleep(0.1)
- if quit: #global variable to stop the code
- break
- def get_angle(x, y):
- angle = math.atan2(y,x)/math.pi*180
- return angle
- def joystick():
- global angle
- while True
- x, y = joysticl_get_x_and_y_function_here() ##function to get the joysticks x and y position
- angle = get_angle(x, y) #updates the global angle variable
- if quit: #global variable to stop the code
- break
- def main():
- global angle
- reset_stepper_to_0() ##function to reset the stepper motor to its 0th place if needed
- t = threading.Thread(target=update_stepper) #creates thread to run the stepper motor
- t.start() #starts the thread
- t2 = threading.Thread(target=joystick) #creates thread to run the joystick and get the angle variable
- t2.start()
- while True:
- print(angle)
- time.sleep(0.25)
- if quit: #global variable to stop the code
- break
- if __name__ == "__main__":
- try:
- main()
- except KeyboardInterrupt:
- quit = True
- except:
- raise
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement