Last active
August 29, 2015 14:15
-
-
Save walterhiggins/d0d432688dcda8c54eda to your computer and use it in GitHub Desktop.
Updated arduino-light code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var mqtt = require('sc-mqtt'), | |
slash = require('slash'), | |
client = mqtt.client('tcp://localhost:1883','sc-ard-light'), | |
preDawn = 22000, | |
JavaString = java.lang.String; | |
client.connect(); | |
client.subscribe('arduino-light'); | |
var max = 0; | |
function updateTime(topic, message){ | |
var val = +(new JavaString(message.payload)); | |
if (val > max && (val - max < 10)){ | |
max = val; | |
} | |
var rawTime = preDawn + (val * (8000/max)); | |
var time = Math.floor(rawTime % 24000); | |
slash('time set ' + time , server); | |
} | |
client.onMessageArrived(updateTime); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment