def digitalWrite(gpio_pin, state): """ Writes given digital pin low if state=0, high otherwise. """ assert (gpio_pin in GPIO), "*Invalid GPIO pin: '%s'" % gpio_pin gpio_file = getGPIOStateFile(gpio_pin) if not os.path.exists(gpio_file): print "warning: digitalWrite() failed, pin '%s' not exported." % gpio_pin +\ " Did you call pinMode()?" return if (state): sysfs.kernelFilenameIO(gpio_file, '1') else: sysfs.kernelFilenameIO(gpio_file, '0')
def digitalRead(gpio_pin): """ Returns input pin state as 1 or 0. """ assert (gpio_pin in GPIO), "*Invalid GPIO pin: '%s'" % gpio_pin gpio_file = getGPIOStateFile(gpio_pin) return int(sysfs.kernelFilenameIO(gpio_file))