![Yoctopuce Yocto-Display User Manual Download Page 48](http://html1.mh-extra.com/html/yoctopuce/yocto-display/yocto-display_user-manual_3418946048.webp)
await l0.lineTo(5, 0);
await l0.moveTo(0, h - 6);
await l0.lineTo(0, h - 1);
await l0.lineTo(5, h - 1);
await l0.moveTo(w - 1, h - 6);
await l0.lineTo(w - 1, h - 1);
await l0.lineTo(w - 6, h - 1);
await l0.moveTo(w - 1, 5);
await l0.lineTo(w - 1, 0);
await l0.lineTo(w - 6, 0);
// draw a circle in the top left corner of layer 1
l1 = await disp.get_displayLayer(1);
await l1.clear();
await l1.drawCircle(h / 8, h / 8, h / 8);
// and animate the layer
x = 0;
y = 0;
vx = 1;
vy = 1;
refresh();
}
async function refresh() {
if (await disp.isOnline()) {
x += vx;
y += vy;
if ((x
< 0
)
||
(
x >
w - (h / 4))) vx = -vx;
if ((y
< 0
)
||
(
y >
h - (h / 4))) vy = -vy;
await l1.setLayerPosition(x, y, 0);
} else {
document.getElementById('msg').value ='Module not connected';
}
setTimeout(refresh, 5);
}
startDemo();
<
/
script
>
<
/
head
>
<
body
>
Module to use:
<
input
id
=
'serial'><
span
style
=
'color:red;border:none;'
id
=
'msg'><
/
span
><
br
>
<
/
body
>
<
/
html
>
No installation is needed to run this example, all you have to do is open the HTML file using a web
browser,
9.4. Control of the module part
Each module can be controlled in a similar manner, you can find below a simple sample program
displaying the main parameters of the module and enabling you to activate the localization beacon.
"use strict"
;
require
(
'yoctolib-es2017/yocto_api.js'
);
async
function
startDemo
(
args
)
{
await
YAPI
.
LogUnhandledPromiseRejections
();
// Setup the API to use the VirtualHub on local machine
let
errmsg
=
new
YErrorMsg
();
if(await
YAPI
.
RegisterHub
(
'127.0.0.1'
,
errmsg
)
!=
YAPI
.
SUCCESS
)
{
console.
log
(
'Cannot contact VirtualHub on 127.0.0.1: '
+
errmsg.
msg
);
return;
}
// Select the relay to use
let
module
=
YModule
.
FindModule
(
args
[
0
]);
if(await
module.
isOnline
())
{
if(
args.
length
>
1
)
{
if(
args
[
1
]
==
'ON'
)
{
9. Using Yocto-Display with JavaScript / EcmaScript
42
www.yoctopuce.com
Summary of Contents for Yocto-Display
Page 1: ...Yocto Display User Manual...
Page 2: ......
Page 40: ...34 www yoctopuce com...
Page 52: ...46 www yoctopuce com...
Page 84: ...78 www yoctopuce com...
Page 92: ...86 www yoctopuce com...
Page 130: ...124 www yoctopuce com...
Page 422: ...416 www yoctopuce com...