Item code: 27800
The 2-Axis Joystick provides a simple and convenient way to add X-Ycontrol to a project. A potentiometer attached to each axis providesproportional feedback of the up/down and left/right positions. Thejoystick is spring-loaded, so that it always returns to its centeredposition when you release it.
Depending on the microcontroller you use, a small assortment ofexternal components is required to complete the connection. These arenoted in the Parts List. Refer to the appropriate diagram under Basic Wiring.
The examples in this KickStart display the instantaneous values ofthe X and Y (Left/Right, and Up/Down) axes of the joystick. The valuesare displayed in a debug window or serial monitor.
The range of values returned is dependent on the type of interfaceused between the joystick and microcontroller. The values noted beloware approximate, and are based on the circuitry described in Basic Wiring.
Microcontroller | Range | Center Position |
---|---|---|
BASIC Stamp | 1–60 | 30 |
Propeller | 0–6000 | 3000 |
Arduino | 0–1023 | 512 |
Download BASIC Stamp 2 code for the 2-Axis Joystick
' {$STAMP BS2}
' {$PBASIC 2.5}UDPin CON 8LRPIn CON 9LR VAR WordUD VAR WordDOHIGH LRPinPAUSE 2RCTIME LRPin, 1, LRHIGH UDPinPAUSE 2RCTIME UDPin, 1, UDDEBUG HOME, "UD = ", DEC UD, ", LR = ", DEC LR, CLREOLPAUSE 50LOOP
Note: When this program is run the BASIC Stamp Debug Terminal will automatically open.
Download Propeller Spin code for the 2-Axis Joystick
OBJpst : "FullDuplexSerial"rc : "RCTime"CON_clkmode = xtal1 + pll16x_xinfreq = 5_000_000PUB Go | UD, LRpst.start(31, 30, 0, 115200)repeatrc.rctime(0, 1, @LR)rc.rctime(1, 1, @UD)pst.Str(String("UD = "))pst.dec(UD)pst.Str(String(", LR = "))pst.dec(LR)pst.tx(13)waitcnt(clkfreq / 2 + cnt) ' 1/2 second delay
Important!This program uses the FullDuplexSerial.spin and RCtime.spin objectlibraries, which are included with the Propeller Tool software download.
Note: To view the results of the demonstration,after uploading is complete run the Parallax Serial Terminal from theRun menu, or press F12. Momentarily depress the Reset button on thePropeller QuickStart board to restart the program.
Download Arduino 1.0 Code for the 2-Axis Joystick
Download Arduino Pre-release Version Code for the 2-Axis Joystick
This program code is compatible with Arduino 1.0 and earlier versions.
int UD = 0;int LR = 0;void setup() {Serial.begin(9600);}void loop() {UD = analogRead(A0);LR = analogRead(A1);Serial.print("UD = ");Serial.print(UD, DEC);Serial.print(", LR = ");Serial.println(LR, DEC);delay(200);}
Note: To view the results of thedemonstration, after uploading is complete click the Serial Monitor iconin the Arduino IDE. This displays the Serial Monitor window.Momentarily depress the Reset button on the Arduino board to restart thesketch
联系客服