The Joystick module is similar to analog joysticks found in gamepads. It is made made by mounting two potentiometers at a 90 degrees angle. The potentiometers are connected to a short stick centered by springs.
Output: This module will output roughly 2.5 volts from both outputs when in its resting position. Moving the stick will cause the outputs to change from 0v to 5v depending on its direction. If you connect this module to an Arduino through the Tinkerkit Shield, you can expect to read a value of roughly 512 in its resting position (expect small variations due to tiny imprecisions of the springs and mechanism) When you move the joystick you should see the values change from 0 to 1023 depending on its position.
Module Description: This module features two 4k7 Ohm linear potentiometers, two standard TinkerKit 3pin connector, two signal amplifiers, a green LED that signals that the module is correctly powered and two yellow LED whose brightness depends on the values output by the module.
This module is a SENSOR. Its connectors are OUTPUTs which must be be connected to two of the INPUTconnectors on the TinkerKit Shield.
/*
Joystick
Reads two analog input pins; a T000030 Joystick Module Analog Sensor
connected to I0 and I1, uses the result to set the brightness of two
T010111 LED Module connected on O0 and O1.
Also prints the results to the serial monitor.
created 7 dec 2010
by Davide Gomba
modified on Dec 2011
by Federico Vanzati
This example code is in the public domain.
*/
// include the TinkerKit library
#include <TinkerKit.h>
// creating the object ‘joystick’ that belongs to the ‘TKJoystick’ class
// and giving the values to the desired input pins
TKJoystick joystick(I0, I1);
// creating the objects ‘xLed’ & ‘yLed’
// that both belongs to the ‘TKLed’ class
// and giving the values to the desired output pins
TKLed xLed(O0), yLed(O1);
int xAxisValue = 0; // value read from the Joystick’s x-axis
int yAxisValue = 0; // value read from the Joystick’s y-axis
void setup()
{
// initialize serial communications at 9600 bps
Serial.begin(9600);
}
void loop()
{
// read the both joystick axis values:
xAxisValue = joystick.getXAxis();
yAxisValue = joystick.getYAxis();
// set the leds brightness
xLed.brightness(xAxisValue);
yLed.brightness(yAxisValue);
// print the results to the serial monitor:
Serial.print("Joystick X = " );
Serial.print(xAxisValue);
Serial.print("\t Joystick Y = " );
Serial.print(yAxisValue);
// wait 10 milliseconds before the next loop
// for the analog-to-digital converter to settle
// after the last reading:
delay(10);
}
