I am trying to implement the code below on a raspberry pi with node.js. This code is just an extension of the example found here https://github.com/maugdog/max31855 and trying to implement a while loop to run this forever. When I try to implement a while loop, the temperatures never print out on the console but if I use for loops it seems to work (unless I use a for loop with statement 1 and statement 3 omitted which is what I have read is basically a while loop). Any idea what I am doing wrong? This code calls out other functions such as the max31855 and I have gone into that and put some 'console.log' instructions to try and determine where the code hangs but I have not been successful in figuring this out. I thought maybe this has to do with the callback features of node.js but I just don't know. This is basic code so not sure what fundamental flaw I am making.
Example code to read once:
var max31855 = require('max31855');
var thermoSensor = new max31855();
thermoSensor.readTemp(function(temp) {
thermoSensor.readTempC(function(temp) {
console.log('Temp in degrees celsius: ', temp);
});
My code to read over and over:
while(true){
var max31855 = require('max31855');
var thermoSensor = new max31855();
thermoSensor.readTemp(function(temp) {
thermoSensor.readTempC(function(temp) {
console.log('Temp in degrees celsius: ', temp);
});
}