Added support for user animations with docs

This commit is contained in:
Kyle Brown
2019-03-16 14:26:19 -07:00
parent 9d8682c866
commit 3f8c6e7648
5 changed files with 96 additions and 13 deletions

View File

@@ -1,8 +1,8 @@
import time
from math import e, exp, pi, sin
from micropython import const
import pulseio
from micropython import const
led_config = {
'brightness_step': 5,
@@ -12,6 +12,7 @@ led_config = {
'animation_speed': 1,
}
class led:
brightness = 0
time = int(time.monotonic() * 1000)
@@ -25,6 +26,7 @@ class led:
animation_mode = 'static'
animation_speed = 1
enabled = True
user_animation = None
def __init__(self, led_pin, config):
self.led = pulseio.PWMOut(led_pin)
@@ -33,6 +35,8 @@ class led:
self.animation_mode = const(config['animation_mode'])
self.animation_speed = const(config['animation_speed'])
self.breathe_center = const(config['breathe_center'])
if config['user_animation']:
self.user_animation = config['user_animation']
def __repr__(self):
return 'LED({})'.format(self._to_dict())
@@ -131,6 +135,8 @@ class led:
return self.effect_breathing()
elif self.animation_mode == 'static':
return self.effect_static()
elif self.animation_mode == 'user':
return self.user_animation(self)
else:
self.off()