Merge pull request #295 from dastels/master

Code for Auto Sunglasses
This commit is contained in:
Limor "Ladyada" Fried 2018-08-15 08:36:35 -07:00 committed by GitHub
commit 2db17be1ff
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

37
AutoSunglasses/code.py Normal file
View file

@ -0,0 +1,37 @@
"""
Circuit Playground Express auto-sunglasses/flashlight
Adafruit invests time and resources providing this open source code.
Please support Adafruit and open source hardware by purchasing
products from Adafruit!
Written by Dave Astels for Adafruit Industries
Copyright (c) 2018 Adafruit Industries
Licensed under the MIT license.
All text above must be included in any redistribution.
"""
import time
import board
import simpleio
from adafruit_circuitplayground.express import cpx
servo = simpleio.Servo(board.A1)
cpx.pixels.fill((0, 0, 0))
servo.angle = 90
while True:
light_level = cpx.light
if light_level < 10:
cpx.pixels.fill((200, 200, 200))
else:
cpx.pixels.fill((0, 0, 0))
if light_level < 200:
servo.angle = 90
else:
servo.angle = 0
time.sleep(0.25)