Skip to content

Commit 0fdc528

Browse files
committed
remaining exmplz
1 parent 97e7e05 commit 0fdc528

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-0
lines changed

examples/pcf8575_blink16outputs.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2022 ladyada for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: Unlicense
4+
5+
import time
6+
import board
7+
import adafruit_pcf8575
8+
9+
print("PCF8575 16 output LED blink test")
10+
11+
i2c = board.I2C()
12+
pcf = adafruit_pcf8575.PCF8575(i2c)
13+
14+
while True:
15+
pcf.write_gpio(0x5555) # set every other pin high
16+
time.sleep(0.2)
17+
pcf.write_gpio(0xAAAA) # toggle high/low pins
18+
time.sleep(0.2)

examples/pcf8575_buttonled.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2022 ladyada for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: Unlicense
4+
5+
import time
6+
import board
7+
import digitalio
8+
import adafruit_pcf8575
9+
10+
print("PCF8575 digitalio LED + button test")
11+
12+
i2c = board.I2C()
13+
pcf = adafruit_pcf8575.PCF8575(i2c)
14+
15+
# get a 'digitalio' like pin from the pcf
16+
led = pcf.get_pin(8)
17+
button = pcf.get_pin(0)
18+
19+
# Setup pin7 as an output that's at a high logic level default
20+
led.switch_to_output(value=True)
21+
# Setup pin0 as an output that's got a pullup
22+
button.switch_to_input(pull=digitalio.Pull.UP)
23+
24+
25+
while True:
26+
led.value = button.value
27+
time.sleep(0.01) # debounce

examples/pcf8575_read16inputs.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2022 ladyada for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: Unlicense
4+
5+
import time
6+
import board
7+
import adafruit_pcf8575
8+
9+
print("PCF8575 16 input button test")
10+
11+
i2c = board.I2C()
12+
pcf = adafruit_pcf8575.PCF8575(i2c)
13+
14+
15+
# turn on all 16 weak pullups
16+
pcf.write_gpio(0xFFFF)
17+
18+
while True:
19+
vals = pcf.read_gpio()
20+
for b in range(16):
21+
if not vals & (1 << b):
22+
print("button #%d pressed" % b)
23+
time.sleep(0.01) # debounce delay

0 commit comments

Comments
 (0)