Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Raspberry pi simpel coding
#3
(May-22-2019, 12:42 PM)DeaD_EyE Wrote: You could add this two methods to your class StopWatch.

    def cb_start(self, channel):
        self.Start()
        
    def cb_stop(self, channel):
        self.Stop()
This two methods are called from outside by GPIO.add_event_detect.
The code which should setup the inputs and set the event detection.

def set_gpio(start_pin, stop_pin, start_cb, stop_cb):
    GPIO.setmode(GPIO.BOARD)
    GPIO.setup(start_pin, GPIO.IN)
    GPIO.setup(stop_pin, GPIO.IN)
    GPIO.add_event_detect(start_pin, GPIO.RISING, callback=start_cb, bouncetime=200)
    GPIO.add_event_detect(stop_pin, GPIO.RISING, callback=stop_cb, bouncetime=200)
Then add to Main after creation of a StopWatch instance, the set_gpio function call:

In Main():
stopWatch = StopWatch(root)
set_gpio(38, 36, stopWatch.cb_start, stopWatch.cb_stop)
stopWatch.pack(side=TOP)

More info about the GPIO functions are here: https://sourceforge.net/p/raspberry-gpio...ki/Inputs/


Thank you, for youre respons :)
i have tryed youre code, but it will stil not work for me :/
Reply


Messages In This Thread
Raspberry pi simpel coding - by mike3001 - May-22-2019, 10:18 AM
RE: Raspberry pi simpel coding - by DeaD_EyE - May-22-2019, 12:42 PM
RE: Raspberry pi simpel coding - by mike3001 - May-22-2019, 03:38 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Coding for Python and Raspberry pi beast 3 48,883 Sep-21-2021, 09:56 PM
Last Post: beast

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020