Hello!
I’m playing around with the big Skywriter and progress was good, but now I’m stuck.
What I’m trying to do is to control some rgb-lights via mqtt. The mqtt works super nice with the flick-actions, but I’m having trouble with the move-function.
My problem is that I can’t figure out how to use a change in the z-value to adjust brightness, perhaps my beginner-level python can explain my thinking better than words?
#!/usr/bin/python
# -*- coding: utf-8 -*-
import paho.mqtt.client as mqtt
import skywriter
from os import system
import time
import signal
R = 0
G = 0
B = 0
old_z = float(0)
new_z = float(0)
def on_connect(client, userdata, rc):
client.subscribe('all/huzzah/rgb')
client.subscribe('all/rpi_rgb')
client.subscribe('all/rpi_rgb_R')
client.subscribe('all/rpi_rgb_G')
client.subscribe('all/rpi_rgb_B')
def on_message(client, userdata, msg):
global R
global G
global B
rgb_payload = msg.payload
r_payload = int(rgb_payload.split(',')[0])
g_payload = int(rgb_payload.split(',')[1])
b_payload = int(rgb_payload.split(',')[2])
R = r_payload
G = g_payload
B = b_payload
@skywriter.flick()
def flick(start,finish):
if(start == "north" and finish == "south"):
print "north - south"
client.publish("all/huzzah/rgb", "1024, 1024, 1024")
elif(start == "south" and finish == "north"):
print "south - north"
client.publish("all/huzzah/rgb", "1024, 0, 0")
elif(start == "west" and finish == "east"):
print "west - east"
client.publish("all/huzzah/rgb", "0, 1024, 0")
else:
print "Invalid"
@skywriter.move()
def move(x, y, z):
global old_z
old_z = float(z)
print old_z
print type(old_z)
time.sleep(0.2)
def move_new(x, y, z):
global new_z
new_z = float(z)
print "blopp"
print new_z
def diff():
z_diff = old_z - new_z
print z_diff
signal.pause()
#def old_z(x, y, z):
# z_old = float(z)
# print z_old
# round_z_old = round(z_old,3)
# print round_z_old
# sleep(0.5)
#def new_z(x, y, z):
# z_new = float(z)
# round_z_new = round(z_new,3)
#z_diff = round_z_old - round_z_new
#print z_diff
client = mqtt.Client()
client.on_connect = on_connect
client.username_pw_set('user', 'pass')
client.on_message = on_message
client.connect('192.x.x.x', port, 5)
client.loop_forever(timeout=1.0, max_packets=1)