Contrôle De La Partie Module - Yoctopuce Yocto-Color Mode D'emploi

Table des Matières

Publicité

public static void main(String[] args)
try {
// setup the API to use local VirtualHub
YAPI.RegisterHub("127.0.0.1");
} catch
(YAPI_Exception
System.out.println("Cannot contact VirtualHub on 127.0.0.1 ("
ex.getLocalizedMessage()
System.out.println("Ensure that the VirtualHub application is
System.exit(1);
}
YColorLed led1,led2;
if
(args.length
led1 =
led2 =
} else {
led1 = YColorLed.FirstColorLed();
if
(led1 ==
System.out.println("No module connected (check USB
System.exit(1);
}
led2 = led1.nextColorLed();
}
int
all_colors[]
for(int
color :
try {
System.out.println(String.format("Change color to
led1.set_rgbColor(color);//led2.rgbMove(color, 1000); // smooth transition
led2.rgbMove(color, 1000);
YAPI.Sleep(1000);
} catch
System.out.println("Module not connected (check identification and USB
cable)");
break;
}
}
YAPI.FreeAPI();
}
}
15.3. Contrôle de la partie module
Chaque module peut-être contrôlé d'une manière similaire, vous trouverez ci-dessous un simple
programme d'exemple affichant les principaux paramètres d'un module et permettant d'activer la
balise de localisation.
import
com.yoctopuce.YoctoAPI.*;
import
java.util.logging.Level;
import
java.util.logging.Logger;
public class
Demo
public static void main(String[] args)
{
try {
// setup the API to use local VirtualHub
YAPI.RegisterHub("127.0.0.1");
} catch
(YAPI_Exception
System.out.println("Cannot contact VirtualHub on 127.0.0.1 ("
ex.getLocalizedMessage()
System.out.println("Ensure that the VirtualHub application is
System.exit(1);
}
System.out.println("usage: demo [serial or logical name]
YModule module;
if
(args.length
module = YModule.FirstModule();
if
(module ==
System.out.println("No module connected (check USB
System.exit(1);
www.yoctopuce.com
ex) {
+ ")");
>
0) {
YColorLed.FindColorLed(args[0]
YColorLed.FindColorLed(args[0]
null) {
= {0xff0000,0x00ff00,0x0000ff};
all_colors) {
(YAPI_Exception
ex) {
{
ex) {
+ ")");
==
0) {
null) {
{
+ ".colorLed1");
+ ".colorLed2");
// smooth transition
15. Utilisation du Yocto-Color en Java
+
running");
cable)");
0x%06x", color));
+
running");
[ON/OFF]");
cable)");
97

Publicité

Table des Matières
loading

Table des Matières