37 lines
1.2 KiB
Python
37 lines
1.2 KiB
Python
import threading
|
|
from time import perf_counter
|
|
from telemetrix_rpi_pico import telemetrix_rpi_pico
|
|
import time
|
|
from kuukar_config import LEDS_DATA_PIN, LEDS_NUM
|
|
|
|
|
|
class leds:
|
|
flashing = False
|
|
start_time = perf_counter()
|
|
def __init__(self, aux_board: telemetrix_rpi_pico.TelemetrixRpiPico) -> None:
|
|
self.aux_board = aux_board
|
|
self.aux_board.set_pin_mode_neopixel(LEDS_DATA_PIN, LEDS_NUM)
|
|
|
|
def flash(self,r: int, g: int, b: int, duration: int):
|
|
if not self.flashing:
|
|
self.flashing = True
|
|
self.start_time = perf_counter()
|
|
threading.Thread(target=self.__flasher__,args=(r,g,b,duration))
|
|
|
|
|
|
@staticmethod
|
|
def __blink_func__(t: float,dur: float):
|
|
if t>dur:
|
|
return 0
|
|
return (-1/(dur/2.0)**2)*(t-dur/2.0)**2+1
|
|
|
|
def __get_time__(self) -> float:
|
|
return perf_counter()-self.start_time
|
|
|
|
def __flasher__(self, r: int, g: int, b: int, duration: int):
|
|
while True:
|
|
print(leds.__blink_func__(self.__get_time__(),duration))
|
|
time.sleep(0.05)
|
|
if self.__get_time__ > duration:
|
|
flashing = False
|
|
break |