Page 140 - Programming the Photon Getting Started With the Internet of Things
P. 140
dist = parseFloat(data.result);
dist = dist.toFixed(2);
dist_gauge.refresh(dist);
setTimeout(getDistanceReading, 1000);
}
}
function getDistanceReading(){
$.get(distance_url, {access_token: accessToken}, callbackDistance);
}
</script>
</head>
<body>
<div id="distanceGauge" ></div>
<script>
var dist_gauge = new JustGage({
id: "distanceGauge",
value: 0,
min: 5,
max: 250,
title: "Rangefinder (cm)"
});
getDistanceReading();
</script>
</body>
</html>
In the HTML all we really need to do here is change the values to match the variable
in our program on the Photon. For this example we are going to measure the distance in
centimeters, so we need to change the following URL to reflect that:
var distance_url = "https://api.spark.io/v1/devices/" + deviceID + "/distan
ceCM";
You also need to change the script for the gauge to change the maximum and
minimum values to those our range finder can detect. According to the datasheet, this is in
the range of 5 to 250 cm. When you load the webpage in the browser as shown in Figure
6.15, you should see the distance of the nearest object to the sensor. Try moving your hand
closer and refreshing the page; this should change the value.