Commit 36b3ec9f authored by Federico Meloda's avatar Federico Meloda

new power function in led

parent 78872364
...@@ -26,9 +26,8 @@ class Color: ...@@ -26,9 +26,8 @@ class Color:
class ColorManager(Thread): class ColorManager(Thread):
current_rand = 1 current_rand = 1
unscaled_blue = 100
current_color = Color(0, 0, 0) current_color = Color(0, 0, 0)
activeFlag = True stato = 0
spi = spidev.SpiDev() spi = spidev.SpiDev()
running = True running = True
...@@ -44,38 +43,56 @@ class ColorManager(Thread): ...@@ -44,38 +43,56 @@ class ColorManager(Thread):
def get_color(self): def get_color(self):
if self.current_color.green + self.current_rand > 80: if self.current_color.green + self.current_rand > 80:
self.current_rand = -randint(1, 8) self.current_rand = -randint(1, 8)
self.current_color = Color(80, 255, self.current_color.blue) self.current_color = Color(80, 255, 30)
elif self.current_color.green + self.current_rand < 0: elif self.current_color.green + self.current_rand < 0:
self.current_rand = randint(1, 8) self.current_rand = randint(1, 8)
self.current_color = Color(0, 255, self.current_color.blue) self.current_color = Color(0, 255, 30)
else: else:
self.current_color.green += self.current_rand self.current_color.green += self.current_rand
self.current_color.red = 255 self.current_color.red = 255
self.current_color.blue = self.unscaled_blue * self.current_color.green//255 self.current_color.blue = 30
if self.unscaled_blue < 100:
self.unscaled_blue += 1
def power(self):
if self.current_color.green + self.current_rand > 20:
self.current_rand = -randint(1, 4)
self.current_color = Color(30, 255, 0)
elif self.current_color.green + self.current_rand < 0:
self.current_rand = randint(1, 8)
self.current_color = Color(0, 255, 0)
else:
self.current_color.green += self.current_rand
self.current_color.red = 255
if self.pow_time < 0 : self.stato = 0
def fade(self): def fade(self):
if self.current_color.red > 0: if self.current_color.red > 0:
self.current_color.red -= 1 self.current_color.red -= 1
if self.current_color.green > 0: if self.current_color.green > 0:
self.current_color.green -= 1 self.current_color.green -= 1
if self.current_color.blue > 0:
self.current_color.blue -= 1
def stop(self): def stop(self):
self.running = False self.running = False
def start_fade(self): def start_fade(self):
self.activeFlag = False self.stato = 2
def start_pow(self):
self.stato = 1
def burn(self):
self.unscaled_blue = 0
def run(self): def run(self):
while self.running: self.running:
if self.activeFlag: if self.stato == 0: self.get_color()
self.get_color() elif self.stato == 1: self.power()
else: elif self.stato == 2: self.fade()
self.fade() }
switch[self.stato]()
ws2812.write2812(self.spi, [self.current_color.as_tuple() * 4]) ws2812.write2812(self.spi, [self.current_color.as_tuple() * 4])
sleep(0.001) sleep(0.001)
...@@ -108,9 +125,10 @@ def main(): ...@@ -108,9 +125,10 @@ def main():
if messagedata == b"liftoff": if messagedata == b"liftoff":
cm = ColorManager() cm = ColorManager()
cm.start() cm.start()
cm.burn() cm.start_pow()
elif messagedata == b"stage_1_separation": elif messagedata == b"stage_1_separation":
cm.burn() cm.burn()
cm.start_pow()
elif messagedata == b"stage_2_separation": elif messagedata == b"stage_2_separation":
cm.burn() cm.burn()
cm.start_fade() cm.start_fade()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment