From 7920773e4283107f6529f62ba077ebc1b7c6f68e Mon Sep 17 00:00:00 2001 From: Paul RATHGEB Date: Wed, 4 Feb 2015 23:19:42 +0100 Subject: [PATCH] Fixed this example --- examples/webService/bgColorLEDWEB/index.html | 8 +- examples/webService/bgColorLEDWEB/main.py | 79 ++++++++++---------- 2 files changed, 44 insertions(+), 43 deletions(-) diff --git a/examples/webService/bgColorLEDWEB/index.html b/examples/webService/bgColorLEDWEB/index.html index 424e230e..e063511b 100755 --- a/examples/webService/bgColorLEDWEB/index.html +++ b/examples/webService/bgColorLEDWEB/index.html @@ -1,7 +1,7 @@ - + @@ -48,9 +48,9 @@ function changeColorFromWeio(data) { rgb = "rgb("+ - String(data.data.red) + "," + - String(data.data.green) + "," + - String(data.data.blue) + ")"; + String(data.red) + "," + + String(data.green) + "," + + String(data.blue) + ")"; //console.log(data.data.red); $("body").css("background-color", rgb); //console.log(data); diff --git a/examples/webService/bgColorLEDWEB/main.py b/examples/webService/bgColorLEDWEB/main.py index 6748f03f..121bb57b 100755 --- a/examples/webService/bgColorLEDWEB/main.py +++ b/examples/webService/bgColorLEDWEB/main.py @@ -1,72 +1,73 @@ from weioLib.weio import * - + import colorsys import time - + +def setup(): + # Attaches interrupt from Web client to "message" string + attach.event('message', buttonHandler) + attach.process(potar) + sharedVar[0] = 0 + def buttonHandler(dataIn) : if dataIn is not None : #print dataIn #print "FROM BROWSER: ", dataIn["data"], " uuid: ", dataIn["uuid"] beta = float(dataIn) - + # put limiters if (beta>88): beta = 88 if (beta<-88): beta = -88 - + # map interval between -88 and 88 to 0.0 - 1.0 hue = proportion(beta,-88.0,88.0, 0.0,1.0) - # drive HUE color and transform to rgb for LED + # drive HUE color and transform to rgb for LED rgb = colorsys.hsv_to_rgb(hue, 1.0, 1.0) - - + + # rgb output is 0.0-1.0 transform to 0-255 - red = int(rgb[0]*255.0) - green = int(rgb[1]*255.0) - blue = int(rgb[2]*255.0) - - print red, " ", green, " ", blue + red = int(rgb[0]*100.0) + green = int(rgb[1]*100.0) + blue = int(rgb[2]*100.0) + + print red, " ", green, " ", blue # Export color to LED setColor(red,green,blue) - + def setColor(r,g,b): - pwmWrite(19,b) - pwmWrite(20,r) - pwmWrite(21,g) - - colorData = {} - colorData["red"] = r - colorData["green"] = g - colorData["blue"] = b - - for client in shared.connectedClients : - client.connection.emit("usrMsg", colorData) - + pwmWrite(19,b) + pwmWrite(20,r) + pwmWrite(21,g) + + colorData = {} + colorData["red"] = r + colorData["green"] = g + colorData["blue"] = b + + serverPush("usrMsg", colorData) + def potar() : val = 0 val_p = 0 while True: val = analogRead(25) - + if (abs(val-val_p)>10): hue = proportion(val,0,1023, 0.0,1.0) - # drive HUE color and transform to rgb for LED + # drive HUE color and transform to rgb for LED rgb = colorsys.hsv_to_rgb(hue, 1.0, 1.0) - + # rgb output is 0.0-1.0 transform to 0-255 - red = int(rgb[0]*255.0) - green = int(rgb[1]*255.0) - blue = int(rgb[2]*255.0) - + red = int(rgb[0]*100.0) + green = int(rgb[1]*100.0) + blue = int(rgb[2]*100.0) + setColor(red,green,blue) - + val_p = val time.sleep(0.05) - + def proportion(value,istart,istop,ostart,ostop) : - return float(ostart) + (float(ostop) - float(ostart)) * ((float(value) - float(istart)) / (float(istop) - float(istart))) - -# Attaches interrupt from Web client to "message" string -attach.event('message', buttonHandler) -attach.process(potar) \ No newline at end of file + return float(ostart) + (float(ostop) - float(ostart)) * ((float(value) - float(istart)) / (float(istop) - float(istart))) \ No newline at end of file