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.

halfer
  • 19,824
  • 17
  • 99
  • 186
  • That error message should have also included a trackback, which indicates on which line the error is occuring. Can you identify on which line the error occurs? – Robᵩ Apr 23 '14 at 15:49

1 Answers1

0

You seem to be passing the window handle of the slider. You want to pass a number.

Try this:

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)
Robᵩ
  • 163,533
  • 20
  • 239
  • 308
  • Alternatively, if you meant for the slider to control the duty cycle, `freq = 60` and `duty_cycle = self.slider.GetValue()`. – Robᵩ Apr 23 '14 at 16:01
  • Thanks for your response. The code does not return the error as before so is an improvement, however does not actually control the brightness of the LED, rather when the slider is released the LED is just turned off :s – user3564614 Apr 28 '14 at 10:57