<html>
<head>
<title>BOLT</title>
<script type="text/javascript" src="/serveFile?filename=bolt.js"> setDebug(true); </script>
<script>
var output;
var sensor_output;
var sensor_output_array;
var sensor_val;
function start(){
//the format of the digital or analog read provided in bolt.js is "Pin Value=x"
// so instead of just writing my own ajax request or editing the js file like a normal person
// i decided to do it like coz i was lazy
digitalRead(3,"hidden");
sensor_output= document.getElementById("hidden").innerHTML;
sensor_output_array = sensor_output.split("=");
sensor_val=sensor_output_array[1];
if(sensor_val==0){
document.getElementById("light").innerHTML ="something detected";
digitalWrite(5,HIGH);
}
else{
document.getElementById("light").innerHTML ="all clear";
digitalWrite(5,LOW);
}
document.getElementById("output").innerHTML =sensor_val;
//anything less than 2.5 seconds causes alot of problems for me.
// it hangs the board and i gotto restart it.
//im assuming its because it take that long to handle one request but i might be wrong.
//if anyone has a reason for this i would like to know
setTimeout(start,3000);
}
</script>
</head>
<body bgcolor="#01FFFF" >
<center>
<h3> Sensor data</h3>
<span id="hidden" style="display: none"> </span>
<span id="output"> </span>
<p id="light"></p></center>
<button onclick="start();">ON</button>
</body>
</html>
Comments