Yoctopuce Yocto-RangeFinder Mode D'emploi page 55

Table des Matières

Publicité

#include "yocto_api.h"
#include "yocto_rangefinder.h"
#include "yocto_lightsensor.h"
#include "yocto_temperature.h"
#include <iostream>
#include <stdlib.h>
using namespace
std;
static void
usage(void)
{
cout
<<
"usage: demo <serial_number> "
cout
<<
"
cout
<<
"
u64
now
= YAPI::GetTickCount();
while (YAPI::GetTickCount() -
// wait 3 sec to show the message
}
exit(1);
}
int main(int
argc,
{
string
errmsg;
string
target;
YRangeFinder
*rf;
YLightSensor
*ir;
YTemperature
*tmp;
if
(argc
< 2) {
usage();
}
target
= (string) argv[1];
// Setup the API to use local USB devices
if
(YAPI::RegisterHub("usb",
cerr
<<
"RegisterHub error: "
return 1;
}
if
(target
== "any") {
rf
= YRangeFinder::FirstRangeFinder();
if
(rf
== NULL) {
cout
<<
"No module connected (check USB cable)"
return 1;
}
target
= rf->get_module()->get_serialNumber();
} else {
rf
=
YRangeFinder::FindRangeFinder(target
}
ir
=
YLightSensor::FindLightSensor(target
tmp
=
YTemperature::FindTemperature(target
while(1) {
if (!rf->isOnline()) {
cout
<<
"Module not connected (check identification and USB
break;
}
cout
<<
"Distance
cout
<<
"Ambient IR
cout
<<
"Temperature : "
cout
<<
"
(press Ctrl-C to exit)"
YAPI::Sleep(1000,
};
YAPI::FreeAPI();
return 0;
}
www.yoctopuce.com
demo <logical_name>"
demo any"
<< endl;
now
< 3000) {
const char
* argv[])
errmsg) != YAPI::SUCCESS) {
<<
errmsg
: "
<< rf->get_currentValue() << endl;
: "
<< ir->get_currentValue() << endl;
<< tmp->get_currentValue() << endl;
errmsg);
<< endl;
<< endl;
<< endl;
<< endl;
+ ".rangeFinder1");
+ ".lightSensor1");
+ ".temperature1");
<< endl;
9. Utilisation du Yocto-RangeFinder en C++
cable)";
49

Publicité

Table des Matières
loading

Table des Matières