Format Blinky Eyes

This commit is contained in:
Craig Richardson 2018-05-14 17:55:50 +01:00
parent d5829fdee4
commit 42fc4881f3

View file

@ -1,11 +1,12 @@
# Name: Blinking Eyes - based on code by Brad Blumenthal, MAKE Magazine """
# License: GPLv3 Blinking Eyes - based on code by Brad Blumenthal, MAKE Magazine
# 2013 - Adafruit Learning System - Modified for 8 MHz ATTiny85 and low light photocell License: GPLv3
# 2018 - Adafruit Learning System - Modified for Gemma M0 and Circuit Python """
import board
import analogio
import time import time
import analogio
import board
import pulseio import pulseio
try: try:
@ -36,16 +37,16 @@ blink_freq_max = 6
while True: while True:
# turn on LEDs if it is dark out # turn on LEDs if it is dark out
if ( photocell.value < darkness_max ): if photocell.value < darkness_max:
# blink frequency and timer # blink frequency and timer
if ( blink_delay ): if blink_delay:
blink_delay = False blink_delay = False
blink_timer_start = time.monotonic() blink_timer_start = time.monotonic()
blink_freq = random.randint(blink_freq_min, blink_freq_max) blink_freq = random.randint(blink_freq_min, blink_freq_max)
# time to blink? Blink once every 3 - 6 seconds (random assingment) # time to blink? Blink once every 3 - 6 seconds (random assingment)
if ( ( time.monotonic() - blink_timer_start ) >= blink_freq ): if (time.monotonic() - blink_timer_start) >= blink_freq:
blink_delay = True blink_delay = True
pwm.duty_cycle = 0 pwm.duty_cycle = 0
time.sleep(.1) time.sleep(.1)
@ -57,10 +58,10 @@ while True:
brightness = brightness + fade_amount brightness = brightness + fade_amount
# reverse the direction of the fading at the ends of the fade: # reverse the direction of the fading at the ends of the fade:
if ( brightness <= 0 ): if brightness <= 0:
fade_amount = -fade_amount fade_amount = -fade_amount
counter += 1 counter += 1
elif ( brightness >= 65535 ): elif brightness >= 65535:
fade_amount = -fade_amount fade_amount = -fade_amount
counter += 1 counter += 1