int read_word_2c(int
{
val;
int
val
=
wiringPiI2CReadReg8(fd, addr);
val
=
val
<<
8;
val
+=
wiringPiI2CReadReg8(fd, addr+1);
if
(val
>=
0x8000)
val
=
-(65536
-
val;
return
}
double dist(double
{
return
sqrt((a
a)
+
*
}
double get_y_rotation(double
{
double
radians;
radians
=
atan2(x, dist(y, z));
return
-(radians
*
}
double get_x_rotation(double
{
double
radians;
radians
=
atan2(y, dist(x, z));
return
(radians
(180.0
*
}
int
main()
{
fd
=
wiringPiI2CSetup (0x68);
wiringPiI2CWriteReg8
printf("set
0x6B=%X\n",wiringPiI2CReadReg8 (fd,0x6B));
while(1) {
gyroX
=
read_word_2c(0x43);
gyroY
=
read_word_2c(0x45);
gyroZ
=
read_word_2c(0x47);
gyroX_scaled
=
gyroY_scaled
=
gyroZ_scaled
=
//Print values for the X, Y, and Z axes of the gyroscope sensor.
printf("My gyroX_scaled:
delay(100);
printf("My gyroY_scaled:
delay(100);
printf("My gyroZ_scaled:
delay(100);
acclX
=
read_word_2c(0x3B);
acclY
=
read_word_2c(0x3D);
1.8. 2 Eingabe
addr)
val);
a,
double
b)
(b
b));
*
x,
double
(180.0
/
M_PI));
x,
double
/
M_PI));
(fd,0x6B,0x00);//disable sleep mode
gyroX
/
131.0;
gyroY
/
131.0;
gyroZ
/
131.0;
%f\n", gyroY X_scaled);
%f\n", gyroY Y_scaled);
%f\n", gyroY Z_scaled);
y,
double
z)
y,
double
z)
SunFounder Da Vinci Kit
(Fortsetzung der vorherigen Seite)
(Fortsetzung auf der nächsten Seite)
261