Temperature and light sensor

Posted on
  • Hey,

    So I have a puckjs running off a webpage. When I use the light sensor and try to get temperature at the same time. The output of the temperature is the light reading instead of current temp. Works fine when run separately. Any ideas? Apologise for the JQuery. Just playing around with Puck for now!!! Thanks.

    $(".temperature").click(function() {
        Puck.eval("E.getTemperature()", function(y) {
            console.log(y);
            $('.currentTemp').text(y);
        })
        $(".main_content_wrap").addClass("rain")­;
        createRain();
    });
    
    connection.write("reset();\n", function() {
                // Wait for it to reset itself
    
                setTimeout(function() {
                    // Now tell it to write data on the current light level to Bluetooth
                    // 10 times a second
                    connection.write("setInterval(function()­{Bluetooth.println(Puck.light());},100);­\n",
                        function() { console.log("Ready..."); });
    
                }, 1500);
            });
    
  • Ahh - yes, it's because you're mixing the two methods of communication - the simple Puck.write/eval and the more complicated connection one.

    You have two choices really:

    • just use the simple version (so add a Puck.eval("(Puck.light()", ...) to get the light level when you need it)
    • Modify the connection version to print both the light and the temperature:

    connection.write("setInterval(function()­{Bluetooth.println([Puck.light(),E.getTe­mperature()]);},100);\n", ...
    

    You could find other ways to work around it, but I'd say those are your easiest options

  • Awesome thanks. Will try.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Temperature and light sensor

Posted by Avatar for Ciaran @Ciaran

Actions