Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. <html>
  2. <head>
  3. <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
  4. <link rel="stylesheet" href="http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.min.css" />
  5. <script src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
  6. <script src="http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.min.js"></script>
  7. </head>
  8. <body>
  9.   <div id="divAction">standby</div>  
  10.   <br />
  11.  
  12.   <table width="100%">
  13.   <tr>
  14.     <td colspan=3>
  15.         <input id="btnForward" onclick="goForward();" type="button" value="forward"/>
  16.     </td>
  17.   </tr>
  18.   <tr >
  19.     <td><input type="button" value="left" onclick="goLeft();"/></td>
  20.     <td><input type="button" value="stop" onclick="stop();"/></td>
  21.     <td><input type="button" value="right" onclick="goRight();"/></td>
  22.   </tr>
  23.   <tr>
  24.     <td colspan=3>
  25.         <input type="button" value="backwards" onclick="goBackwards();"/>
  26.     </td>
  27.   </tr>
  28.   </table>
  29.  
  30.    
  31. </body>
  32. </html>
  33. <script type="text/javascript" language="javascript">
  34.     var activePin = 0;
  35.  
  36.     function goForward() {
  37.         stopMovement();
  38.         activePin = 1;
  39.         digitalPin(1);
  40.         $("#divAction").text("going forward");
  41.      }
  42.  
  43.      function goBackwards() {
  44.          stopMovement();
  45.          activePin = 2;
  46.          digitalPin(2);
  47.          $("#divAction").text("going back");
  48.      }
  49.  
  50.      function goLeft() {
  51.          stopMovement();
  52.          activePin = 3;
  53.          digitalPin(3);
  54.          $("#divAction").text("going left");
  55.     }
  56.  
  57.     function goRight() {
  58.         stopMovement();
  59.         activePin = 4;
  60.         digitalPin(4);
  61.         $("#divAction").text("going right");
  62.     }
  63.  
  64.     function stop() {
  65.         stopMovement();
  66.         $("#divAction").text("Stopped");
  67.     }
  68.  
  69.     function stopMovement() {
  70.         if (activePin != 0) {
  71.             digitalPin(activePin);
  72.             activePin = 0;
  73.         }
  74.     }
  75.  
  76.     var xhttp;
  77.  
  78.     function createXMLHttpRequest() {
  79.         if (window.ActiveXObject) {
  80.             try {
  81.                 // IE 6 and higher
  82.                 xhttp = new ActiveXObject("MSXML2.XMLHTTP");
  83.             } catch (e) {
  84.                 try {
  85.                     // IE 5
  86.                     xhttp = new ActiveXObject("Microsoft.XMLHTTP");
  87.                 } catch (e) {
  88.                     xhttp = false;
  89.                 }
  90.             }
  91.         } else if (window.XMLHttpRequest) {
  92.             try {
  93.                 // Mozilla, Opera, Safari ...
  94.                 xhttp = new XMLHttpRequest();
  95.             } catch (e) {
  96.                 xhttp = false;
  97.             }
  98.         }
  99.     }
  100.  
  101.     function sendRequest(addr) {
  102.         if (!xhttp) {
  103.             alert("An Error occured when trying to initialize XMLHttpRequest!");
  104.             return;
  105.             // exit
  106.         }
  107.         xhttp.open("GET", addr, false);
  108.         xhttp.send(null);
  109.         return xhttp.responseXML;
  110.     }
  111.  
  112.     function digitalPin(pin) {
  113.         xml = sendRequest("switchDigitalPin?pin=" + pin);
  114.         //alert("http request sent");
  115.         //on = xmlDoc.getElementsByTagName("pin" + pin)[0].childNodes[0].nodeValue;
  116.         //alert(on);
  117.  
  118.         //drawDigitalPin(pin, on);
  119.     }
  120.  
  121.     function init() {
  122.         createXMLHttpRequest();
  123.     }
  124.  
  125.  
  126.     window.onload = init;
  127.  
  128.    
  129.    
  130.  
  131.   </script>