Execute Widgets with Change in Screen Orientation

The iPod Touch and iPhone have an accelerometer that adjusts the screen orientation (among other things). You can tap into the orientation and execute widgets depending on the orientation of the device by using a simple HTML file with some Javascript. Put an HTML file on a web server that you can get to on your iPod Touch or iPhone.

Part of the Apple Web Kit is the command “onorientationchange”. We will use that to detect the orientation change and call a script called “updateOrientation()”.

Add the following command to the BODY tag:


Place the following function in the HEAD of the document and call certain widgets at the specific orientation angles of 0°, -90°, and 90°. You can call any type of widget adjusting the position of a servo, controlling a digital output, or setting the state of an X10 widget.

function updateOrientation(){
case 0: widgetExecute("Upright Widget ID");
case -90: widgetExecute("Right Widget ID");
case 90: widgetExecute("Left Widget ID");

Place the widgets referenced in the BODY of the document.


The full iTurn web app is on the Wiki: