Advertisement
Guest User

Untitled

a guest
Mar 2nd, 2015
375
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 3.16 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <!--
  4. This is an app that demonstrates how to control an Arduio board
  5. with TCP over WiFi from the mobile device and a WiFi shield or
  6. an Ethernet shield.
  7.  
  8. Please note that you must enter the IP-address of the Arduino
  9. for this example to work.
  10. -->
  11. <head>
  12.  
  13.     <meta charset="utf-8">
  14.     <meta name="viewport" content="width=device-width, user-scalable=no
  15.         initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0" />
  16.  
  17.     <title>Arduino LED On/Off TCP</title>
  18.  
  19.     <style>
  20.         @import 'ui/css/evothings-app.css';
  21.     </style>
  22.  
  23.     <script>
  24.     // Redirect console.log to Evothings Workbench.
  25.     if (window.hyper && window.hyper.log) { console.log = hyper.log }
  26.     </script>
  27.  
  28.     <script src="cordova.js"></script>
  29.     <script src="libs/jquery/jquery.js"></script>
  30.     <script src="libs/evothings/evothings.js"></script>
  31.     <script src="libs/evothings/arduinotcp/arduinotcp.js"></script>
  32.  
  33. </head>
  34.  
  35. <body ontouchstart=""><!-- ontouchstart="" enables low-delay CSS transitions. -->
  36.  
  37.     <header>
  38.         <h1>Arduino Ethernet Control</h1>
  39.     </header>
  40.  
  41.  
  42.  
  43.     <h2>Enter IP-address of the Arduino</h2>
  44.  
  45.     <input id="ArduinoIpAddress" value="192.168.114.103" type="url" />
  46.     <br/>
  47.     <button class="green" onclick="app.connect()">CONNECT</button>
  48.     <button class="charcoal" onclick="app.disconnect()">DISCONNECT</button>
  49.  
  50.     <br />
  51.  
  52.     <p>Status: <span id="ArduinoStatus">Not connected</span></p>
  53. </br>
  54. <h2>LED 1</h2>
  55.     <button class="green" onclick="app.ledOn()">LED ON</button>
  56.     <button class="red" onclick="app.ledOff()">LED OFF</button>
  57. <h2>LED 2</h2>
  58.     <button class="green" onclick="app.led2On()">LED ON</button>
  59.     <button class="red" onclick="app.led2Off()">LED OFF</button>
  60. <h2>LED 3</h2>    
  61.     <button class="green" onclick="app.led3On()">LED ON</button>
  62.     <button class="red" onclick="app.led3Off()">LED OFF</button>
  63.    <p><span id="led3state">n/a</span></p>
  64.  
  65.     <script>
  66.     // Short name for Arduino TCP library.
  67.     var arduino = evothings.arduinotcp
  68.  
  69.     // Application object.
  70.     var app = {}
  71.  
  72.     // Pin for LED.
  73.     app.pin = 2
  74.     app.pin2 = 4
  75.     app.pin3 = 7
  76.  
  77.     // Turn on LED.
  78.     app.ledOn = function()
  79.     {
  80.         app.writePin(app.pin, HIGH)
  81.     }
  82.     app.led2On = function()
  83.     {
  84.         app.writePin(app.pin2, HIGH)
  85.     }
  86.     app.led3On = function()
  87.     {
  88.         app.writePin(app.pin3, HIGH)
  89.     }
  90.  
  91.     // Turn off LED.
  92.     app.ledOff = function()
  93.     {
  94.         app.writePin(app.pin, LOW)
  95.     }
  96.     app.led2Off = function()
  97.     {
  98.         app.writePin(app.pin2, LOW)
  99.     }
  100.     app.led3Off = function()
  101.     {
  102.         app.writePin(app.pin3, LOW)
  103.     }
  104.     app.writePin = function(pin, value)
  105.     {
  106.         arduino.pinMode(pin, OUTPUT)
  107.         arduino.digitalWrite(pin, value)
  108.     }
  109.    
  110. app.digitalRead = function()
  111.     {
  112.         arduino.digitalRead(app.pin, function(data)
  113.         {
  114.             $('#led3state').html('Digital value of pin is: ' + data)
  115.         })
  116.     }
  117.    
  118.     app.connect = function()
  119.     {
  120.         arduino.connect($('#ArduinoIpAddress').val(), 3300, function(success)
  121.         {
  122.             if (success)
  123.             {
  124.                 $('#ArduinoStatus').html('Connected to the Arduino')
  125.                 app.digitalRead()
  126.             }
  127.             else
  128.             {
  129.                 $('#ArduinoStatus').html('Connection error')
  130.             }
  131.         })
  132.     }
  133.  
  134.     app.disconnect = function()
  135.     {
  136.         arduino.disconnect()
  137.         $('#ArduinoStatus').html('Disconnected')
  138.     }
  139.    
  140.    
  141.     </script>
  142.  
  143. </body>
  144.  
  145. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement