-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_mcp41010.py
executable file
·47 lines (40 loc) · 1.22 KB
/
test_mcp41010.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env python
#
import time
import spi.mcp41010
from RPi import GPIO
SPI_MOSI = 26
SPI_CS = 13
SPI_CLK = 19
def pulse_led(low_val=(1 << 6), high_val=(1 << 7), step=1):
"""
Pulse an LED connect to an MCP41010 digital potentiometer and a 220 ohm
resistor.
"""
mcp41010 = spi.mcp41010.MCP41010(clk=SPI_CLK, cs=SPI_CS, mosi=SPI_MOSI, miso=None, verbose=False)
while True:
### pulse from a lower resistance to a higher one
for value in range(low_val, high_val, step):
mcp41010.set_value(value)
time.sleep(0.01)
### pulse from a higher resistance back to a lower one
for value in range(high_val, low_val, -1 * step):
mcp41010.set_value(value)
time.sleep(0.01)
def scale_range():
"""
Cycle through every value that the MCP41010 is capable of using
"""
mcp41010 = spi.mcp41010.MCP41010(clk=SPI_CLK, cs=SPI_CS, mosi=SPI_MOSI, miso=None, verbose=True)
for value in range( (1 << 8) ):
mcp41010.set_value(value)
time.sleep(0.01)
try:
input("Press return to continue ")
except:
pass
if __name__ == '__main__':
try:
pulse_led()
except KeyboardInterrupt:
pass