私は多くの異なる位置にウィジェットの矩形を追加するためのクラスを作成します。 Im return run error GPIOのほとんどの設定()、11行目のポートを設定する、私のコードで何が問題になっていますか?Python Kivy RaspberrypiエラーGPIOチャンネル
> Traceback (most recent call last): File "plantadeira.py", line 50,
> in <module>
> MainApp().run() File "/usr/local/lib/python2.7/dist-packages/kivy/app.py", line 828, in run
> runTouchApp() File "/usr/local/lib/python2.7/dist-packages/kivy/base.py", line 487, in
> runTouchApp
> EventLoop.window.mainloop() File "/usr/local/lib/python2.7/dist-packages/kivy/core/window/window_egl_rpi.py",
> line 90, in mainloop
> self._mainloop() File "/usr/local/lib/python2.7/dist-packages/kivy/core/window/window_egl_rpi.py",
> line 85, in _mainloop
> EventLoop.idle() File "/usr/local/lib/python2.7/dist-packages/kivy/base.py", line 327, in
> idle
> Clock.tick() File "/usr/local/lib/python2.7/dist-packages/kivy/clock.py", line 581, in
> tick
> self._process_events() File "kivy/_clock.pyx", line 368, in kivy._clock.CyClockBase._process_events
> (/tmp/pip-NKJIwl-build/kivy/_clock.c:7219) File "kivy/_clock.pyx",
> line 398, in kivy._clock.CyClockBase._process_events
> (/tmp/pip-NKJIwl-build/kivy/_clock.c:7102) File "kivy/_clock.pyx",
> line 396, in kivy._clock.CyClockBase._process_events
> (/tmp/pip-NKJIwl-build/kivy/_clock.c:7032) File "kivy/_clock.pyx",
> line 168, in kivy._clock.ClockEvent.tick
> (/tmp/pip-NKJIwl-build/kivy/_clock.c:3109) File "plantadeira.py",
> line 26, in update
> if self.read_Sensor(pin) == False: File "plantadeira.py", line 36, in read_Sensor
> sensor = GPIO.wait_for_edge(int(pin), GPIO.RISING, timeout=1000) RuntimeError: You must setup() the GPIO channel as an input first
これは私のコードのpythonです:
from kivy.app import App
from kivy.clock import Clock
from kivy.graphics import Color, Rectangle
from kivy.properties import NumericProperty
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.widget import Widget
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.IN, pull_up_down = GPIO.PUD_DOWN)
pin_1 = 17
class MainLayout(FloatLayout):
pass
class bar(Widget):
r = NumericProperty(1)
def __init__(self, pin, p1, p2, s1, s2, **kwargs):
super(bar, self).__init__(**kwargs)
Clock.schedule_interval(self.update, 0.5)
def update(self, pin):
if self.read_Sensor(pin) == False:
with self.canvas:
Color(self.r, 0, 0, 1)
Rectangle(pos=(p1,p2), size=(s1,s2))
else:
with self.canvas:
Color(self.r, 1, 1, 1)
Rectangle(pos=(p1,p2), size=(s1,s2))
def read_Sensor(self, pin):
sensor = GPIO.wait_for_edge(int(pin), GPIO.RISING, timeout=1000)
if sensor is None:
return False
else:
return True
class MainApp(App):
def build(self):
self.mainlayout = Widget()
bar1 = bar(pin_1, 1, 10, 60, 100)
self.mainlayout.add_widget(bar1)
return self.mainlayout
if __name__ == '__main__':
MainApp().run()
おかげで非常に多く、仕事! –
@ VictorSued great。問題ない。 – EL3PHANTEN