Yoctopuce Yocto-3D-V2 Mode D'emploi page 169

Module électronique de 51x20mm qui dispose d'un accéléromètre, d'un gyroscope et d'un magnétomètre
Table des Matières

Publicité

#import <Foundation/Foundation.h>
#import "yocto_api.h"
#import "yocto_tilt.h"
#import "yocto_compass.h"
#import "yocto_gyro.h"
#import "yocto_accelerometer.h"
static void
usage(void)
{
NSLog(@"usage: demo <serial_number>
NSLog(@"
demo
NSLog(@"
demo any
exit(1);
}
int main(int
argc,
{
NSError
*error;
if
(argc <
2) {
usage();
}
@autoreleasepool {
// Setup the API to use local USB devices
if([YAPI
RegisterHub:@"usb": &error] != YAPI_SUCCESS) {
NSLog(@"RegisterHub error:
return
1;
}
NSString
*target
YTilt
*anytilt, *tilt1, *tilt2;
YCompass
*compass;
YAccelerometer
YGyro
*gyro;
if([target
isEqualToString:@"any"]) {
anytilt
=
[YTilt
if
(anytilt
NSLog(@"No module connected (check USB
return
1;
}
} else {
anytilt
=
[YTilt
if(![anytilt
NSLog(@"Module not connected (check identification and USB
return
1;
}
}
NSString
*serial
// retrieve all sensors on the device matching the serial
tilt1
=
[YTilt
tilt2
=
[YTilt
compass
=
[YCompass
accelerometer
gyro
=
[YGyro
int
count
=
0;
while(1) {
if(![tilt1
isOnline]) {
NSLog(@"device
break;
}
if
((count
% 10) == 0)
NSLog(@"tilt1\ntilt2\ncompass\tacc\tgyro");
NSLog(@"%f\n%f\n%f\t%f\t%f",
[tilt1 get_currentValue],
[tilt2 get_currentValue],
[compass get_currentValue],
[accelerometer get_currentValue],
[gyro get_currentValue]);
count++;
[YAPI
Sleep:250:NULL];
}
[YAPI
FreeAPI];
}
www.yoctopuce.com
");
<logical_name>");
const char
* argv[])
%@", [error localizedDescription]);
=
[NSString
stringWithUTF8String:argv[1]];
*accelerometer;
FirstTilt];
== NULL) {
FindTilt:[target stringByAppendingString:@".tilt1"]];
isOnline]) {
=
[[anytilt
get_module]
FindTilt:[serial stringByAppendingString:@".tilt1"]];
FindTilt:[serial stringByAppendingString:@".tilt2"]];
FindCompass:[serial stringByAppendingString:@".compass"]];
=
[YAccelerometer
FindAccelerometer:[serial
@".accelerometer"]];
FindGyro:[serial stringByAppendingString:@".gyro"]];
disconnected");
20. Utilisation du Yocto-3D-V2 en Objective-C
(use any discovered
device)");
cable)");
get_serialNumber];
stringByAppendingString:
cable)");
161

Publicité

Table des Matières
loading

Ce manuel est également adapté pour:

Yocto-3d

Table des Matières