A collection of examples for using the gpiozero library for reading sensors and activating actuators
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
837 B

#remember to enable SPI in raspi-config > interfaces before you run this the first time
#How to wire the MCP3008:
#gpiozero about MCP3008:
#gpiozero tools to modify values:
from gpiozero import MCP3008, PWMLED
from gpiozero.tools import clamped, smoothed, scaled
from time import sleep
ldr = MCP3008(channel=0, device=0)
led = PWMLED(17)
while True:
reading = smoothed(ldr,3) #smooth samples
value = scaled(reading, 0,1.0,0.01,0.5) #scale samples
brightness = clamped(value,0,1.0) #clamp samples
for i in brightness:
if i < 0.15:
i = 0
led.value = i