Exemplo n.º 1
0
class Application:
    def __init__(self, **kwargs):
        self.verbose = kwargs.get('verbose', DEFAULT_VERBOSE)
        self.webcam = Webcam(**kwargs)
        self.gpio = GPIO(inputs = INPUT_PINS, outputs = OUTPUT_PINS)
            
        
    def main_loop(self):
        i = 0
        try:
            self.gpio.export()
            while True:
                button_state = self.gpio[SNAP_BUTTON_PIN]
                self.gpio[SNAP_LED_PIN] = button_state
                if button_state:
                    dt = datetime.datetime.now()
                    filename_prefix = dt.strftime("%Y-%m-%d_%H_%M_%S")
                    filename_suffix = "_img%03d" % i
                    self.webcam.take_photo(filename_prefix = filename_prefix,
                                           filename_suffix = filename_suffix,
                                           blocking = True,
                                           )
                    self.gpio[SNAP_LED_PIN] = button_state
                time.sleep(SLEEP_TIME)
        except KeyboardInterrupt:
            if self.verbose:
                print "user aborted capture...goodbye"
        finally:
            self.gpio.unexport()
Exemplo n.º 2
0
    def __init__(self, pin):
        GPIO.export(pin)
        GPIO.direction(pin, GPIO.DIR_OUT)

        self._pin = pin
        self._value = GPIO.VAL_LOW