Since we've added the new 'Variable Servo Position" widget, we are able to expose a few more control functions in javascript.
widgetGetString- use this to get the position from a variable servo position widget
- the format is
widgetGetString('WidgetID'), where WidgetID is the 12 character widget ID
widgetSetString- use this to set the servo position
- the format is
widgetSetString('WidgetID','Position'), where WidgetID is the 12 character widget ID and a PWM servo position
Just like the other ioBridge javascript functions, you'll need to actually include the widget on the webpage for these to work. However you can hide the widget from view if you want.
As an example, I used these two new function to make a servo increment/decrement type control on for my fishcam.
http://www.picobay.com/fishcam/fishcamInc.htmlHere is the source code:
<html>
<title>Servo Control Example</title>
<head>
<script type="text/javascript">
function moveServo(widgetID, direction, distance){
distance = parseInt(distance);
current = parseInt(widgetGetString(widgetID));
if (direction == "CCW") {
distance = current-distance;
}
else {
distance = current+distance;
}
widgetSetString(widgetID, distance);
current = Math.round(29 - (current - 800) * 60 / 500);
document.getElementById("ServoPosition").innerHTML = current + "°";
}
</script>
</head>
<body onload="moveServo('k7bgNMyCTW9b', 'CW', '0')">
<iframe name="livecam" id="livecam" width="320" height="240" src="http://www.picobay.com/fishcam/inside.html" frameborder="0" allowtransparency="false" scrolling="no" ></iframe>
<br><br>
Click the arrow buttons to move pan the camera.
<br><br>
<form><input type="button" Name="CamLeft" Value="<-" onClick="moveServo('k7bgNMyCTW9b', 'CW', '40')"><input type="button" Name="CamRight" Value="->" onClick="moveServo('k7bgNMyCTW9b', 'CCW', '40')"></form>
Camera Servo Positon = <a id="ServoPosition"></a>
<div id="ioWidgets" style="display:none;">
<script type="text/javascript">document.write(unescape("%3Cscript src='" + "http://www.iobridge.com/widgets/io.js?k7bgNMyCTW9b' type='text/javascript'%3E%3C/script%3E"));</script>
</div>
</body>
</html>