ChromeApps/SerialDevice/main.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<title>Serial Device
</head>
<body>
<div id="main">
<p>The Arduino
sends:</p>
<p id="output"></p>
</div>
<script src="js/serial_device.js"></script>
<script src="js/arduino.js"></script>
</body>
</html>
In the HTML page, you ll find a paragraph element with its
. That s the element we ll fill with the data we read from the serial port.
output
At the end of the document, we include our new JavaScript library for
accessing the serial device. Also, we include a file named
ChromeApps/SerialDevice/js/arduino.js
var
arduino =
new
SerialDevice('/dev/tty.usbmodem24311');
arduino.onConnect.addListener(function() {
console.log('Connected to: '
});
arduino.onReadLine.addListener(function(line) {
console.log('Read line: '
document.getElementById('output').innerText = line;
});
arduino.connect();
Here we create a new
functions for the
onConnect
console. The
onReadLine
Document Object Model (DOM).
Make sure you use the correct serial port in the first line of
connect your Arduino to your computer and upload a sketch that permanently
outputs lines of text on the serial port. You can use the sketch from
Your Own Game Controller, on page
see something like the following figure:
Demo</title>
+ arduino.path);
+ line);
SerialDevice
object named
and
onReadLine
events. Both write a message to the
listener puts the line it has read into the browser s
106. Start the Chrome app, and you should
www.it-ebooks.info
Writing a SerialDevice Class
id
attribute set to
arduino.js
:
arduino
. Then we add listener
arduino.js
Building
279
. Then
report erratum
discuss
Need help?
Do you have a question about the Arduino Uno and is the answer not in the manual?