0

I have basic wxPython knowledge.

I am trying to obtain the slider value and set this as the value for the Pulse width modulation of an LED.

This is the code I have so far:

  • Slider

    slider = wx.Slider (panel, 100, 25, 1, 100, pos=(200,70), size=(250, -1), style= wx.SL_HORIZONTAL | wx.SL_AUTOTICKS | wx.SL_LABELS )
    slider.SetTickFreq(5, 1)
    slider.SetBackgroundColour("light blue")
    self.Bind(wx.EVT_SCROLL_CHANGED, self.OnSlide1)
    
  • Function

    def OnSlide1(self,event):
        PWM_VALUE = event.GetEventObject()
        p = GPIO.PWM(11, PWM_VALUE)
        p.start(0)
    

This returns "TypeError: requires a float" which I believe to mean it needs a floating point.

However I am not sure if the code is close to being correct anyway.

4

1 回答 1

0

您似乎正在传递滑块的窗口句柄。你想传递一个数字。

尝试这个:

self.slider = wx.Slider(...)

# UNTESTED
def OnSlide1(self, event):
  freq = self.slider.GetValue()
  p = GPIO.PWM(11, freq)
  duty_cycle = 0
  p.start(duty_cycle)
于 2014-04-23T15:57:41.750 回答