fix rgb test

This commit is contained in:
Tomas Krejci 2024-05-21 21:50:56 +02:00
parent 5b00bc7304
commit f62b163990

View File

@ -11,7 +11,7 @@ class RGB:
#rgb_pwr = 1.0
def __init__(self):
global rgb_pwr
rgb_pwr = 0.2 # 0.0 - 1.0
rgb_pwr = 0.05 # 0.0 - 1.0
self.led_r = PWM(Pin(22), 100)
self.led_g = PWM(Pin(26), 100)
@ -20,13 +20,13 @@ class RGB:
async def set(self, r, g, b):
global rgb_pwr
self.led_r.duty_u16(int(65535 * float(r) * rgb_pwr))
self.led_g.duty_u16(int(65535 * float(g) * rgb_pwr))
self.led_b.duty_u16(int(65535 * float(b) * rgb_pwr))
self.led_r.duty_u16(int(65535 * r * rgb_pwr))
self.led_g.duty_u16(int(65535 * g * rgb_pwr))
self.led_b.duty_u16(int(65535 * b * rgb_pwr))
await uasyncio.sleep(0.01)
async def on(self):
await self.set(1, 1, 1)
await self.set(0.8, 0.8, 0.8)
async def off(self):
await self.set(0, 0, 0)
@ -41,10 +41,10 @@ class RGB:
async def set_pwr_up(self):
await self.set_pwr(await self.get_pwr() * 2)
await self.set_pwr(await self.get_pwr() * 5.0)
async def set_pwr_down(self):
await self.set_pwr((await self.get_pwr()) * 0.5)
await self.set_pwr((await self.get_pwr()) * 0.2)
async def set_red(self):
await self.set(1, 0, 0)
@ -65,7 +65,7 @@ class RGB:
await self.set(0, 1, 1)
async def set_white(self):
await self.set(1, 1, 1)
await self.set(0.8, 0.8, 0.8)
async def set_orange(self):
await self.set(1, 0.5, 0)
@ -74,11 +74,11 @@ class RGB:
async def test(self):
sec = 3
sec = 1
print("RGB demo")
print("Press Ctrl-C to exit")
await uasyncio.sleep(sec)
print(f"RGB power: {self.get_pwr()}")
print(f"RGB power: {await self.get_pwr()}")
print("RGB initializing...")
await uasyncio.sleep(sec)
@ -95,16 +95,21 @@ class RGB:
print("Blue on")
await self.set_blue()
await uasyncio.sleep(sec)
print("RGB on")
await self.on()
print("White on")
await self.set_white()
await uasyncio.sleep(sec)
print("Red on")
await self.set_red()
await uasyncio.sleep(sec)
print("RGB power down")
await self.set_pwr_down()
print("RGB power:", self.get_pwr())
await self.set_red()
print("RGB power:", await self.get_pwr())
await uasyncio.sleep(sec)
print("RGB power up")
await self.set_pwr_up()
print("RGB power:", self.get_pwr())
await self.set_red()
print("RGB power:", await self.get_pwr())
await uasyncio.sleep(sec)
rgb = RGB()