-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtkcmd.py
More file actions
35 lines (27 loc) · 739 Bytes
/
tkcmd.py
File metadata and controls
35 lines (27 loc) · 739 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/python
# -*- coding: utf-8 -*-
# move a servo from a Tk slider - scruss 2012-10-28
import pyfirmata
from tkinter import *
# don't forget to change the serial port to suit
board = pyfirmata.Arduino('COM8')
# start an iterator thread so
# serial buffer doesn't overflow
iter8 = pyfirmata.util.Iterator(board)
iter8.start()
# set up pin D9 as Servo Output
pin9 = board.get_pin('d:9:s')
def move_servo(a):
pin9.write(a)
# set up GUI
root = Tk()
# draw a nice big slider for servo position
scale = Scale(root,
command = move_servo,
to = 175,
orient = HORIZONTAL,
length = 400,
label = 'Angle')
scale.pack(anchor = CENTER)
# run Tk event loop
root.mainloop()