Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <!--
- This is an app that demonstrates how to control an Arduio board
- with TCP over WiFi from the mobile device and a WiFi shield or
- an Ethernet shield.
- Please note that you must enter the IP-address of the Arduino
- for this example to work.
- -->
- <head>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width, user-scalable=no
- initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0" />
- <title>Arduino LED On/Off TCP</title>
- <style>
- @import 'ui/css/evothings-app.css';
- </style>
- <script>
- // Redirect console.log to Evothings Workbench.
- if (window.hyper && window.hyper.log) { console.log = hyper.log }
- </script>
- <script src="cordova.js"></script>
- <script src="libs/jquery/jquery.js"></script>
- <script src="libs/evothings/evothings.js"></script>
- <script src="libs/evothings/arduinotcp/arduinotcp.js"></script>
- </head>
- <body ontouchstart=""><!-- ontouchstart="" enables low-delay CSS transitions. -->
- <header>
- <h1>Arduino Ethernet Control</h1>
- </header>
- <h2>Enter IP-address of the Arduino</h2>
- <input id="ArduinoIpAddress" value="192.168.114.103" type="url" />
- <br/>
- <button class="green" onclick="app.connect()">CONNECT</button>
- <button class="charcoal" onclick="app.disconnect()">DISCONNECT</button>
- <br />
- <p>Status: <span id="ArduinoStatus">Not connected</span></p>
- </br>
- <h2>LED 1</h2>
- <button class="green" onclick="app.ledOn()">LED ON</button>
- <button class="red" onclick="app.ledOff()">LED OFF</button>
- <h2>LED 2</h2>
- <button class="green" onclick="app.led2On()">LED ON</button>
- <button class="red" onclick="app.led2Off()">LED OFF</button>
- <h2>LED 3</h2>
- <button class="green" onclick="app.led3On()">LED ON</button>
- <button class="red" onclick="app.led3Off()">LED OFF</button>
- <p><span id="led3state">n/a</span></p>
- <script>
- // Short name for Arduino TCP library.
- var arduino = evothings.arduinotcp
- // Application object.
- var app = {}
- // Pin for LED.
- app.pin = 2
- app.pin2 = 4
- app.pin3 = 7
- // Turn on LED.
- app.ledOn = function()
- {
- app.writePin(app.pin, HIGH)
- }
- app.led2On = function()
- {
- app.writePin(app.pin2, HIGH)
- }
- app.led3On = function()
- {
- app.writePin(app.pin3, HIGH)
- }
- // Turn off LED.
- app.ledOff = function()
- {
- app.writePin(app.pin, LOW)
- }
- app.led2Off = function()
- {
- app.writePin(app.pin2, LOW)
- }
- app.led3Off = function()
- {
- app.writePin(app.pin3, LOW)
- }
- app.writePin = function(pin, value)
- {
- arduino.pinMode(pin, OUTPUT)
- arduino.digitalWrite(pin, value)
- }
- app.digitalRead = function()
- {
- arduino.digitalRead(app.pin, function(data)
- {
- $('#led3state').html('Digital value of pin is: ' + data)
- })
- }
- app.connect = function()
- {
- arduino.connect($('#ArduinoIpAddress').val(), 3300, function(success)
- {
- if (success)
- {
- $('#ArduinoStatus').html('Connected to the Arduino')
- app.digitalRead()
- }
- else
- {
- $('#ArduinoStatus').html('Connection error')
- }
- })
- }
- app.disconnect = function()
- {
- arduino.disconnect()
- $('#ArduinoStatus').html('Disconnected')
- }
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement