Ws2812-Matrix10

Aus c3RE.de
Wechseln zu: Navigation, Suche

Die 10x10-RGB-Matrix

MQTT-Topic:

huette/clubraum/000/ws2812Matrix10/frame

huette/clubraum/000/ws2812Matrix10/actuators/set_pixel


Siehe [1] für mehr Infos zur Nutzung

Alle Modes in dezimal:

0	Static
1	Blink
2	Breath
3	Color Wipe
4	Color Wipe Random
5	Random Color
6	Single Dynamic
7	Multi Dynamic
8	Rainbow
9	Rainbow Cycle
10	Scan
11	Dual Scan
12	Fade
13	Theater Chase
14	Theater Chase Rainbow
15	Running Lights
16	Twinkle
17	Twinkle Random
18	Twinkle Fade
19	Twinkle Fade Random
20	Sparkle
21	Flash Sparkle
22	Hyper Sparkle
23	Strobe
24	Strobe Rainbow
25	Multi Strobe
26	Blink Rainbow
27	Chase White
28	Chase Color
29	Chase Random
30	Chase Rainbow
31	Chase Flash
32	Chase Flash Random
33	Chase Rainbow White
34	Chase Blackout
35	Chase Blackout Rainbow
36	Color Sweep Random
37	Running Color
38	Running Red Blue
39	Running Random
40	Larson Scanner
41	Comet
42	Fireworks
43	Fireworks Random
44	Merry Christmas
45	Fire Flicker
46	Fire Flicker (soft)

Einen fortune-Spruch als scrolltext senden:

(echo -n "text #FF0000 "  ; fortune)|mosquitto_pub -h mqtt  -t "huette/clubraum/000/ws2812Matrix10/actuators/set_pixel"  -l

Ein 10x10 pixel Bild (turtle10.png) endlos von links nach rechts durch scrollen:

#!/usr/bin/env python
import time

from PIL import Image
import paho.mqtt.client as mqtt
import ImageOps

topic =        "huette/clubraum/000/ws2812Matrix10/actuators/frame"
topic2 =       "huette/clubraum/000/ws2812Matrix10/actuators/set_pixel"
#topic =         "huette/clubraum/000/ws2812tonne/actuators/frame"
#topic2 =        "huette/clubraum/000/ws2812tonne/actuators/set_pixel"
#topic =        "huette/clubraum/000/redshift/actuators/frame"

def on_connect(client, userdata, flags, rc):
    print("Connected with result code " + str(rc))

client = mqtt.Client()
client.on_connect = on_connect

#client.connect("zero", 1883, 60)
client.connect("mqtt", 1883, 60)

client.loop_start()

# 10x10 pixel image:
filename = "turtle10.png"
#filename = "test10x10.png"
#filename="invaders.png"

im = Image.open(filename)
rot = ImageOps.mirror(im)
rot=rot.rotate(90)
#print im.size
print rot.size

#rot.show()

#convert from RGBA(4 byte per pixel) to RGB(3 byte per pixel)
rgbimg=rot.convert('RGB')
stri = rgbimg.tostring()

b = bytearray()
b.extend(stri)

def turn_it(rot,deg):
    rot=rot.rotate(deg)
    rgbimg=rot.convert('RGB')
    stri = rgbimg.tostring()
    b = bytearray()
    b.extend(stri)
    return b

def move_it(img,deg):    
    a = 1
    b = 0
    c = 0 #left/right (i.e. 5/-5)
    d = 0
    e = 1
    f = -deg #up/down (i.e. 5/-5)
    img = img.transform(img.size, Image.AFFINE, (a, b, c, d, e, f))
    rgbimg=img.convert('RGB')
    stri = rgbimg.tostring()
    b = bytearray()
    b.extend(stri)
    return b


                       
byteArray2 = bytearray([2,2,2,2,2,2,2,2,
                        4,4,4,4,4,4,4,4,
                        8,8,8,8,8,8,8,8,
                        16,16,16,16,16,16,16,16,
                        32,32,32,32,32,32,32,32,
                        64,  64, 64, 64, 64, 64, 64, 64,
                        128,128,128,128,128,128,128,128,
                        1,1,1,1,1,1,1,1])
           
size = 100
byteArray =   bytearray(  [0,0,0]*size )
byteArray2 =  bytearray(  [10,110,0]*size )

print "len bytearry:",len(byteArray )
print "len bytearray2:", len(byteArray2)


client.publish( topic2, "255 #000000")

deg=-10
while True:
    deg =deg+1
    b=move_it(rot,deg)
    #b = turn_it(rot,deg)
    client.publish( topic, b )
    #client.publish( topic, byteArray )
    time.sleep(0.1)
    #print ('A')
    #client.publish( topic, byteArray2)
    #time.sleep(1)
    print ('B', deg)
    if (deg==9):
        deg=-10