Drkcore

12 01 2010 Python 電子工作 Gainer Tweet

Identipong

IPアドレスに応じて色を変えられるのであれば、アクセスログをLEDで光らせればいいんではなかろうか?と思ったので。

参考

  • Identicon
  • Image::Identicon
  • ピンポン玉をLEDのディフューザーに
  • PyGainer

Gainerのほうは秋月で買ったカソードのフルカラーLEDを刺した。抵抗は全て330Ω(それしかなかった)でピンポン球はダイソーかどっかで買った6個入り100円のヤツを錐とドライバーでぐりぐりした。

1223800515

という単純な配線。

アクセスログは自宅サーバーに直接アクセスしてIPアドレスを返すようなCGIを用意した。 今回初めてPyGainerを使ってみた。

import sha,struct,urllib2,time,sys
from time import sleep
from PyGainer import PyGainer
#from random import randint

p = '/dev/cu.usbserial-A2002mCa'
g = PyGainer()
config = { 'baudrate' : 38400, 'timeout' : 5 }

#def rand_rgb():
#    return(randint(0,255),randint(0,255),randint(0,255))

def get_rgb():
    ip = urllib2.urlopen('http://myserver/taillog.cgi').read()

    print ''.join(ip.split('.'))

    s = sha.new(ip).digest()
    code = struct.unpack('5L',s)[0]

    blue  = int((code >> 6) & 0x0ff)
    green = int((code >> 15) & 0x0ff)
    red   = int((code >> 24) & 0x0ff)

    return (blue,green,red)

if g.open(p, config) == 0:
    if g.reset() == True:
        print "RESET"
    else:
        print "ERROR"

    sleep(0.1)
    g.version()
    g.configuration(1)

    sleep(0.1)

    for i in range(100):
        (blue,green,red) = get_rgb()
        g.set_specified_analog_output_port(0, green)     # G
        g.set_specified_analog_output_port(1, blue )     # B
        g.set_specified_analog_output_port(3, red  )     # R
        sleep(3)

    g.set_specified_analog_output_port(0,0)
    g.set_specified_analog_output_port(1,0)
    g.set_specified_analog_output_port(3,0)

    g.close()

動かした。うしろでカチャカチャうるさいのは犬が晩ご飯を催促している音。

Identiconでいうところのパターンのようなものの表現は点滅で実装しようかと思ったが、それって分かりにくいよなと。もう少し面白そうなデバイスはなかろうか。

About

  • もう5年目(wishlistありマス♡)
  • 最近はPythonとDeepLearning
  • 日本酒自粛中
  • ドラムンベースからミニマルまで
  • ポケモンGOゆるめ

Tag

Python Deep Learning javascript chemoinformatics Emacs sake and more...

Ad

© kzfm 2003-2021