File tree Expand file tree Collapse file tree 3 files changed +68
-0
lines changed Expand file tree Collapse file tree 3 files changed +68
-0
lines changed Original file line number Diff line number Diff line change
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 )
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
You can’t perform that action at this time.
0 commit comments