-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_adc_classes.py
45 lines (34 loc) · 1.21 KB
/
test_adc_classes.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
#!/usr/bin/python3
# -*- coding: utf-8 -*-
__author__ = "Thomas Kaulke"
__email__ = "kaulketh@gmail.com"
import time
from sys import stdout
from spi import MCP3208Gpiozero, MCP3208Spidev, MCP3208Adafruit
adc_gzero = MCP3208Gpiozero()
adc_spidev = MCP3208Spidev()
adc_adafr = MCP3208Adafruit()
DELAY = .00001
def test_all_channels(adc, delay: float = DELAY):
print(adc.info)
while True:
stdout.write("\r%s" %
"D0:{0:04} | ".format(adc.read(0)) +
"D1:{0:04} | ".format(adc.read(1)) +
"D2:{0:04} | ".format(adc.read(2)) +
"D3:{0:04} | ".format(adc.read(3)) +
"D4:{0:04} | ".format(adc.read(4)) +
"D5:{0:04} | ".format(adc.read(5)) +
"D6:{0:04} | ".format(adc.read(6)) +
"D7:{0:04}".format(adc.read(7))
)
stdout.flush()
time.sleep(delay)
def test_one_channel(adc, channel: int, delay: float = DELAY):
print(adc.info)
while True:
stdout.write("\r%s" % f"D{channel}:{adc.read(channel)}")
stdout.flush()
time.sleep(delay)
if __name__ == '__main__':
test_all_channels(adc_gzero)