好的我一直在尋找一個例子,現在似乎找不到任何通過I2C向Arduino傳遞tkinter滑塊值的例子。到目前爲止,我還沒有嘗試與Arduino進行溝通。我接下來穿過那座橋;現在我只想弄清楚如何編寫幻燈片widget值並通過I2C發送。Python Tkinter Slider Widget通過I2C寫入數值
下面是Python 2中的一個簡單的GUI slider部件,我相信這是I2C通信的正確設置。我更新了Rpi以建立I2C。我想在Arduino中執行的操作只是讀取伺服控制的值0到180。重要的是它只是寫入值或以某種方式可以用於輸入。如果其他條件得到滿足,我會在驅動相同伺服器的arduino中有其他代碼,然後這些代碼將被忽略。
from Tkinter import*
import RPi.GPIO as GPIO
import time
import smbus
bus = smbus.SMBus=(1)
SLAVE_ADDRESS = 0x04
class App:
def __init__(self, master):
def SendScaleReading(self):
S = scale.get()# Now how do we write this and get the Scale Value and send it??
bus(SLAVE_ADDRESS, ord('S'))#According to an example this should be
#"bus.write_byte(SLAVE_ADDRESS, ord('S'))"
frame = Frame(master)
frame.pack()
scale = Scale(frame, from_=0, to=180, orient=HORIZONTAL, command=SendScaleReading)
scale.grid(row=1, column=1)
root = Tk()
root.wm_title('I2C servo control')
app = App(root)
root.geometry("200x50+0+0")
root.mainloop()