Example #1
0
    def __init__(self):
        self.pinB = 11
        self.pinA = 13

        GPIO.setmode(GPIO.BOARD)
        # The following lines enable the internal pull-up resistors
        # on version 2 (latest) boards
        GPIO.setwarnings(False)
        GPIO.setup(self.pinA, GPIO.IN, pull_up_down=GPIO.PUD_UP)
        GPIO.setup(self.pinB, GPIO.IN, pull_up_down=GPIO.PUD_UP)
        #GPIO.setup(self.button, GPIO.IN, pull_up_down=GPIO.PUD_UP

        self.encoder0Pos = 0

        self.busy = False
        self.clockwise = None
        self.counterclockwise = None

        # Add event detection to the GPIO inputs
        GPIO.add_event_detect(self.pinA,
                              GPIO.FALLING,
                              callback=self.switch_eventA)
Example #2
0
    def __init__(self, callback):
        self.pinA = 10  # was 13
        self.pinB = 9  #was 11
        #		self.button=27	# was 15
        self.callback = callback
        GPIO.setmode(GPIO.BOARD)

        self.left = 0
        self.right = 0
        # The following lines enable the internal pull-up resistors
        # on version 2 (latest) boards
        GPIO.setwarnings(False)
        GPIO.setup(self.pinA, GPIO.IN, pull_up_down=GPIO.PUD_UP)
        GPIO.setup(self.pinB, GPIO.IN, pull_up_down=GPIO.PUD_UP)
        #GPIO.setup(self.button, GPIO.IN, pull_up_down=GPIO.PUD_UP

        # Add event detection to the GPIO inputs
        GPIO.add_event_detect(self.pinA,
                              GPIO.FALLING,
                              callback=self.switch_event)
        GPIO.add_event_detect(self.pinB,
                              GPIO.FALLING,
                              callback=self.switch_event)
        return