
Mit dem Photointerrupter können wir wieder die Helligkeitmessen.
| Anschlüsse Raspberry | Anschlüsse Sensor | 
|---|---|
| GND | – | 
| 5V | + | 
| CH1 | Signal | 
Python
import spidev
import time
import os
import RPi.GPIO as gpio
# SPI Verbindung herstellen
spi = spidev.SpiDev()
spi.open(0,0)
# Liest Daten vom MCP3008
def analogEingang(channel):
  adc = spi.xfer2([1,(8+channel)<<4,0])
  data = ((adc[1]&3) << 8) + adc[2]
  return data
while True:
  print("0: "+str(analogEingang(0)))
  time.sleep(1)