I read that it is possible to conenct buttons on pcf8574 and i also found a schematic.
But odes someone have a working part of code to let this work?
I search google but no Python code to be found.
Thx Pascal.
Code: Select all
#!/usr/bin/env python
import smbus
import time
# i2c address of PCF8574
PCF8574=0x20
# open the bus (0 -- original Pi, 1 -- Rev 2 Pi)
b=smbus.SMBus(0)
# make certain the pins are set high so they can be used as inputs
b.write_byte(PCF8574, 0xff)
while 1:
pins = b.read_byte(PCF8574)
print "%02x" % pins
time.sleep(1)
Code: Select all
if pins == ef:
print "Hallo"
and if i try.:Nameerror: name ef is not defined
Code: Select all
if pins == "ef":
print "Hallo"
Code: Select all
print "%02x" % pins
Code: Select all
if pins == 0xef:
print "Hallo"
Code: Select all
if (pins & 0x01) == 0:
print "Hallo 0"
if (pins & 0x02) == 0:
print "Hallo 1"
if (pins & 0x04) == 0:
print "Hallo 2"
if (pins & 0x08) == 0:
print "Hallo 3"
if (pins & 0x10) == 0:
print "Hallo 4"
if (pins & 0x20) == 0:
print "Hallo 5"
if (pins & 0x40) == 0:
print "Hallo 6"
if (pins & 0x80) == 0:
print "Hallo 7"
Code: Select all
sudo apt-get update
sudo apt-get install python-smbus