apa102 LED亮度控制

时间:2018-07-21 01:52:14

标签: python led google-assistant-sdk

我正在将Tinue的APA102 LED python代码(https://github.com/tinue/APA102_Pi)集成到Raspberry Pi上的Google Assistant SDK中,以控制LED灯条。我可以打开和关闭灯,并更改颜色,但是在更改亮度设置时,遇到了麻烦。我可以从说“将亮度设置为1%”开始,它显示global_brightness通过print函数从旧值到新值的变化。当我说变成红色时,它变成了暗红色。我可以增加几次亮度增量,但是例如,如果我尝试将亮度增量从20%增加到100%,然后说变成红色,它实际上会变暗。我认为可能与将MAX_BRIGHTNESS设置为31有关。但是从4050这样的变化,它仍然变得更加明亮。

import apa102

strip = apa102.APA102(num_led=150, global_brightness=20, mosi = 10, sclk = 11,
                              order='rgb')
strip.clear_strip()

if event.type == EventType.ON_DEVICE_ACTION:
    for command, params in process_device_actions(event, device_id):
        print('Do command', command, 'with params', str(params))
        if command == "action.devices.commands.BrightnessAbsolute":
            if params['brightness']:
                strip.clear_strip()
                print ('Global brightness is ', strip.global_brightness)
                strip.global_brightness = params['brightness']
                print ('The Brightness is', strip.global_brightness)

        if command == "action.devices.commands.ColorAbsolute":
            if params['color']:
                if LEDOnOff == "Off":
                    LEDOnOff = "On"
                strip.clear_strip()
                print('The color is ', params['color'].get('name'), '.')
                for led in range(strip.num_led):
                    strip.set_pixel_rgb(led, 
                    params['color'].get('spectrumRGB')) # make desired 
                    color
                strip.show()

0 个答案:

没有答案
相关问题