As you say, your problem is that takeReading returns immediately - even though it sets a timeout using setTimeout.
takeReading
This is classic JS though. You need to use a callback function:
Sensor.prototype.takeReading = function(callback) { // ... setTimeout(function () { // ... callback(sensorValue); }, w); }; function getAllSensorData() { restemp.takeReading(function(resTempVal) { console.log(resTempVal); }); }
@Gordon started
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
As you say, your problem is that
takeReading
returns immediately - even though it sets a timeout using setTimeout.This is classic JS though. You need to use a callback function: