Mini 2-Axis Analog Thumbstick
.
Project Description
This a Mini 2-Axis Analog Thumbstick from Adafruit. The device sends out a Analog signal on the left and right pins depending on how far in a direction the stick is pushed from 1(left,up) to 0(right,down) with the base value in the middle being around 0.5. The outputs on both sides are the same.
Product Webpages
Thumbstick: https://www.adafruit.com/products/2765
Board: https://www.adafruit.com/products/3246
Hookups for Demo
Mbed Pins | Analog Pins | Comments |
p15 | Left Y pin | |
p16 | Left X pin | |
Right Y pin | Right and Left pins give the same output | |
Right X pin | so are not necessary for the demo | |
Vout | + pins | |
Gnd | - pins |
Demo Code
This code lights the LEDs on the mbed LPC1768 from right to left if the thumbstick is rotated in a clockwise manner. This program outputs the X and Y outputs through the USB serial as well to be read through a software such as Teraterm. The outputs are set and accessed via a library although they are both read in as a simple AnalogIn.
#include "mbed.h" #include "Thumbstick.h" DigitalOut led1(LED1);//Up DigitalOut led2(LED2);//Right DigitalOut led3(LED3);//Down DigitalOut led4(LED4);//Left Thumbstick Thumb(p15,p16); //Ypin,Xpin Serial serial(USBTX, USBRX); int main() { while(1) { serial.printf("Xpin: %f, Ypin: %f \n\r",Thumb.Xcord.read(),Thumb.Ycord.read()); if(Thumb.Xcord.read() < 0.2){led2=1;}//Right else{led2=0;} if(Thumb.Xcord.read() > 0.8){led4=1;}//Left else{led4=0;} if(Thumb.Ycord.read()<0.2){led3=1;}//Down else{led3=0;} if(Thumb.Ycord.read()>0.8){led1=1;}//Up else{led1=0;} } }
Import programThumbstickHelloWorld
Thumbstick demo code
Import libraryThumbstick
Library for thumbstick demo
Please log in to post comments.