mikrobus準拠の LED Driver 3 click を、Linuxから光らせた。
ドライバは NCP5623B
。レジスタアドレスがないデバイスなところに注意。armbianの動いているclearfogを使たけど、カーネルヘッダが入らなかったので、pythonからi2cset
を実行する手抜き。あと、0x00
でチップシャットダウン(全てのLEDをOFFにする)になるはずだけど、LEDがチラつくので、事前にPWMで落とすというチート付き。
-
ncp5623.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
import os from enum import Enum SHUTDOWN = 0x0 MAX_CURRENT = 0x1 PWM1 = 0x2 PWM2 = 0x3 PWM3 = 0x4 def send(reg, val): I2CSET="/usr/sbin/i2cset" I2CBUS=1 CHIP_ADDR=0x38 data_addr = (reg << 5) | (val & 0x1f) cmd = '%s -y %s 0x%02x 0x%02x' % (I2CSET, I2CBUS, CHIP_ADDR, data_addr) os.system(cmd) def red(brightness): return (brightness, 0, 0) def green(brightness): return (0, brightness, 0) def blue(brightness): return (0, 0, brightness) def yellow(brightness): return (brightness, brightness, 0) def purple(brightness): return (0, brightness, brightness) def white(brightness): return (brightness, brightness, brightness) def shutdown(): send(PWM1, 0) send(PWM2, 0) send(PWM3, 0) send(SHUTDOWN, 0) def max_current(val): send(MAX_CURRENT, val & 0x1f) def blink(r, g, b): send(PWM1, r & 0x1f) send(PWM2, g & 0x1f) send(PWM3, b & 0x1f)
-
Sample
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
#!/usr/bin/python3 from time import sleep from ncp5623 import shutdown, max_current, blink, red, green, blue, yellow, purp le, white def step(): return (1, 8, 16, 31) if __name__ == '__main__': shutdown() max_current(0x1f) sleep(1) for i in step(): blink(*red(i)) sleep(0.4) shutdown() sleep(0.4) for i in step(): blink(*green(i)) sleep(0.4) shutdown() sleep(0.4) for i in step(): blink(*blue(i)) sleep(0.4) shutdown() sleep(0.4) for i in step(): blink(*yellow(i)) sleep(0.4) shutdown() sleep(0.4) for i in step(): blink(*purple(i)) sleep(0.4) shutdown() sleep(0.4) for i in step(): blink(*white(i)) sleep(0.4) shutdown() sleep(0.4)