Yoctopuce Yocto-Inclinometer Mode D'emploi page 53

Table des Matières

Publicité

#include "yocto_api.h"
#include "yocto_tilt.h"
#include <iostream>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
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,
target;
YTilt
*anytilt, *tilt1, *tilt2 ,
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;
}
// try to find a valid serial number
if(target
== "any") {
anytilt
= YTilt::FirstTilt();
if
(anytilt
== NULL) {
cout
<<
"No module connected (check USB cable)"
return 1;
}
} else {
anytilt
=
YTilt::FindTilt(target
if (!anytilt->isOnline()) {
cout
<<
"Module not connected (check identification and USB cable)"
return 1;
}
}
string
serial
= anytilt->get_module()->get_serialNumber();
// retrieve all sensors on the device matching the serial
tilt1
=
YTilt::FindTilt(serial
tilt2
=
YTilt::FindTilt(serial
tilt3
=
YTilt::FindTilt(serial
int
count
= 0;
while(1) {
if(!tilt1->isOnline()) {
cout
<<
"device
break;
}
if
((count
% 10) == 0) {
cout
<<
"tilt1\ttilt2\ttilt3"
}
cout
<<
std::setprecision(2) << std::setw(8)
<< tilt1->get_currentValue() <<
<< tilt2->get_currentValue() <<
<< tilt3->get_currentValue()
count++;
YAPI::Sleep(250,
}
YAPI::FreeAPI();
return 0;
www.yoctopuce.com
demo <logical_name>"
demo any"
<< endl;
now
< 3000) {
const char
* argv[])
*tilt3;
errmsg) != YAPI::SUCCESS) {
<<
errmsg
+ ".tilt1");
+ ".tilt1");
+ ".tilt2");
+ ".tilt3");
disconnected";
<< endl;
errmsg);
<< endl;
<< endl;
<< endl;
<< endl;
"\t"
"\t"
<< endl;
9. Utilisation du Yocto-Inclinometer en C++
<< endl;
47

Publicité

Table des Matières
loading

Ce manuel est également adapté pour:

Yclinom1

Table des Matières