Joystick-axis

General discussions about V-USB, our firmware-only implementation of a low speed USB device on Atmel's AVR microcontrollers
Post Reply
Slott

Joystick-axis

Post by Slott » Fri Dec 07, 2012 6:09 pm

Hi,
i read this tutorial: http://codeandlife.com/2012/01/22/avr-a ... al-part-1/ , and the same author wrote a How-To for making an USB-Keyboard via the HID-class, which worked wonderful for me :) Now i´m wondering how to get the output of my ADC to a joystick-axis recognized in the windows "USB- and Gamecontrollers"-dialogue... Thanks in advance,

Slot

ulao
Rank 4
Rank 4
Posts: 481
Joined: Mon Aug 25, 2008 8:45 pm

Re: Joystick-axis

Post by ulao » Sat Dec 08, 2012 4:41 am

Its a bit to get used to but not too hard. This is using the ADC's on an atmega 168/328

Code: Select all

//voltage reader.
#define ADC_VREF_TYPE 0x40
static int read_adc(unsigned char adc_input)
{
   ADMUX=adc_input|ADC_VREF_TYPE;
    _delay_us(150);
    ADCSRA|=0x40; // Start the AD conversion
    while ((ADCSRA & 0x10)==0);// Wait for complete
    ADCSRA|=0x10;
    return ADCW;
}



the init would be

Code: Select all

   ADMUX=0x1;//ADC init
   ADCSRA=0x83;


and you would read in to a report like so - natural your math will be different.

Code: Select all

      reportBuffer[1]= (read_adc(0)/3 + 200);//pc0
      reportBuffer[2]= (read_adc(1)/3 + 200)*-1;//pc1

Post Reply