TKGyro
Module
T000062
T000060
Description
With the constructor TKGyro you can create a software object for each gyro module connected to the TinkerKit Sensor Shield and assign it the physical input pins on which is connected. Because there are two kind of gyro modules that differs only by the outputs amplification, creating the object you have to specify the model, like follow:
TK_X1: is the constant for the 1x module
TK_X4: is the constant for the 4x module
For example if you have a 4x gyro module connected to the input pin I0 and I1, you might write:
TKGyro gyro(I0, I1, TK_4X);
Available methods
| getXAxis() | return the gyro x-axis reanding. It is an analog value from 0 to 1023 |
| getYAxis() | return the gyro y-axis reanding. It is an analog value from 0 to 1023 |
| getXAxisRate() | return the gyro output for the x-axis in its physical range: from -6000°/s to +6000°/s for the 1x module and from -1500°/s to +1500°/s for the 4x module |
| getYAxisRate() | return the gyro output for the x-axis in its physical range: from -6000°/s to +6000°/s for the 1x module and from -1500°/s to +1500°/s for the 4x module |
Example
/*
Gyro
Reads two analog input pins; a T000064 Gyro Module with the x-axis connected to I0 pin
the y-axis connected to the I1 pin and prints the results to the serial monitor.
created on Dec 2011
by Federico Vanzati
This example code is in the public domain.
*/
// include the TinkerKit library
#include <TinkerKit.h>
TKGyro gyro(I0, I1, TK_X4); // creating the object 'gyro' that belongs to the 'TKGyro' class
// and giving the values to the desired input pins
// using the 4x amplified module, insert the TK_4X costant.
void setup()
{
// initialize serial communications at 9600 bps
Serial.begin(9600);
}
void loop()
{
Serial.print("X raw: ");
Serial.print(gyro.getXAxis()); // print x-axis analog value
Serial.print("\trate: ");
Serial.print(gyro.getXAxisRate()); // print the x-axis anguar rate in the range of -/+1500 °/s
Serial.print("\t|\t Y raw: ");
Serial.print(gyro.getYAxis()); // print x-axis analog value
Serial.print("\trate: ");
Serial.println(gyro.getYAxisRate()); // print the x-axis anguar rate in the range of -/+1500 °/s
delay(1000);
}