Skip to content

Commit

Permalink
feat: add python code example to move the motor after hitting a switch
Browse files Browse the repository at this point in the history
  • Loading branch information
PIERROOOTT committed Feb 5, 2024
1 parent c24c415 commit 0abcbee
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions examples/back_switch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import crappy
import tkinter as tk

if __name__ == '__main__':

open_switch = 0

mot = crappy.actuator.Phidget4AStepper(
steps_per_mm=2500,
current_limit=3,
max_acceleration=20,
remote=True,
switch_ports=(5, 6))

mot._check_switch = False
mot.open()
for switch in mot._switches:
if switch.getState() is False:
open_switch = switch.getHubPort()


def gen_speed(value):
mot.set_speed(float(value))


# Creates the graphical interface
root = tk.Tk()
root.title("Motor speed")

if open_switch == 5:
# Create the slider
slider = tk.Scale(root,
from_=0,
to=2,
orient=tk.HORIZONTAL,
length=200,
resolution=0.1,
command=gen_speed)
elif open_switch == 6:
slider = tk.Scale(root,
from_=-2,
to=0,
orient=tk.HORIZONTAL,
length=200,
resolution=0.1,
command=gen_speed)
else:
raise ValueError(f"No switch has been hit or disconnected")

slider.pack(pady=20)

root.mainloop()

0 comments on commit 0abcbee

Please sign in to comment.