Created
February 21, 2022 12:00
-
-
Save crbyxwpzfl/229bc86bbee89eb61fe402c536dcdfae to your computer and use it in GitHub Desktop.
python for 3141 light sensor aptv
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import sys | |
import busio | |
import digitalio | |
import board | |
import adafruit_mcp3xxx.mcp3008 as MCP | |
from adafruit_mcp3xxx.analog_in import AnalogIn | |
characteristic = sys.argv[3].strip("''") | |
if characteristic == "name": | |
print("aptv") | |
sys.exit() | |
# create the spi bus | |
spi = busio.SPI(clock=board.SCK, MISO=board.MISO, MOSI=board.MOSI) | |
# create the cs (chip select) | |
cs = digitalio.DigitalInOut(board.D22) | |
# create the mcp object | |
mcp = MCP.MCP3008(spi, cs) | |
# create an analog input channel on pin 0 | |
chan0 = AnalogIn(mcp, MCP.P0) | |
wert = chan0.value | |
if wert < 40000: | |
print("OCCUPANCY_DETECTED") | |
if wert > 40000: | |
print("OCCUPANCY_NOT_DETECTED") | |
sys.exit() | |
© 2022 GitHub, Inc. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment