I'm doing a test here, and when the sensorValor reaches a certain value, as an example I used the 5 it changed the color of the table where it is being written to green, it is currently in red from there higher than 5 the sensorValor fictional in green and lower than that would turn red.
Bad_3 is the div created to be green, and counter_3 to be red.
I tried this example in the script below, but it did not work:
$(document).ready(function () {
var sensorValor = 0;
var testCounter = 0;
var contaBotao = 0;
var testEnable = false;
var roundedValue = 0;
$.ajaxSetup({ cache: false });
setInterval(function() {
$.get ("IOCounter_3.html", function(result) {
$('#counter_3').text(result.trim());
sensorValor = $('#counter_3').text();
});
});
setInterval(function() {
$.get ("IOCounter_4.html", function(result) {
$('#counter_4').text(result.trim());
sensorValor = $('#counter_4').text();
});
});
setInterval(function() {
$.get ("IOCounter_5.html", function(result) {
$('#counter_5').text(result.trim());
sensorValor = $('#counter_5').text();
});
});
setInterval(function() {
$.get ("IOCounter_6.html", function(result) {
$('#counter_6').text(result.trim());
sensorValor = $('#counter_6').text();
});
});
setInterval(function() {
$.get ("IOCounter_7.html", function(result) {
$('#counter_7').text(result.trim());
sensorValor = $('#counter_7').text();
});
});
setInterval(function() {
$.get ("IOCounter_8.html", function(result) {
$('#counter_8').text(result.trim());
sensorValor = $('#counter_8').text();
});
});
$(".botaonibus").click(function(e) {
$('#contador_3').show();
$('#contador_4').show();
$('#contador_5').show();
$('#contador_6').show();
$('#contador_7').show();
$('#contador_8').show();
$('.meubotao').hide();
$('.ingles').hide();
$('.port').hide();
$('#counter_3').show();
$('#counter_4').show();
$('#counter_5').show();
$('#counter_6').show();
$('#counter_7').show();
$('#counter_8').show();
setInterval(function () {
roundedValue = Math.round(parseFloat(sensorValor) * 100) / 100;
if ((roundedValue >=5) && testEnable) {
$('#bad_3').show();
testEnable = false;
}
else if ((roundedValue <=3) && testEnable) {
$('#contador_3').show();
testEnable = false;
}
}, 50);
var len = $('.testes1 div').length;
// //Se for a primeira vez ele é 0 então não entrará, mas na segunda vez
// ele entra no if e pega a div anterior "testCounter-1"
if(len> testCounter) {
if(contaBotao> 0) {
$('.testes1 div').eq(testCounter - 1).hide();
$('#contador_3').hide();
$('#contador_4').hide();
$('#contador_5').hide();
$('#contador_6').hide();
$('#contador_7').hide();
$('#contador_8').hide();
$('#counter_3').hide();
$('#counter_4').hide();
$('#counter_5').hide();
$('#counter_6').hide();
$('#counter_7').hide();
$('#counter_8').hide();
}
contaBotao++;
$('.testes1 div').eq(testCounter).show();
testCounter++;
if(len == testCounter) {
$('.botaonibus').hide(); //ultima etapa ja chegou
$('.goback').show();
$('#contador_3').hide();
$('#counter_3').hide();
}
else {
$('.botaonibus').html('Next Step');
$('.botaonibus').addClass('proxEtapa1');
}
}
});
});