Pages: [1]   Go Down
Author Topic: 2-Axis Joystick  (Read 1291 times)
0 Members and 1 Guest are viewing this topic.
Florida
Offline Offline
God Member
*****
Karma: 2
Posts: 554
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,

I'm trying to understand how to wire the 2-Axis Joystick I bought…
 
http://www.parallax.com/StoreSearchResults/tabid/768/txtSearch/27800/List/0/SortField/4/ProductID/581/Default.aspx

I know how to wire a standard potentiometer, but I don't know what the U/D stands for on the joy stick. If somebody could tell me how to connect the wires correctly so that I can get two separate readings from the Joystick (one form each potentiometer) I would greatly appreciate it.

Thanks,
Drew Davis
Logged

Dubuque, Iowa, USA
Offline Offline
Edison Member
*
Karma: 29
Posts: 2244
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

U/D stands for Up/Down smiley-wink

The U/D+ pin and L/R+ pin must be connected to 5V. The two GND pins must be connected to GND (actually might only need to connect one to GND; it's not clear from the docs). The U/D pin and L/R pins are then connected to separate analog inputs; you would then analogRead() those pins for the position of the joystick.
Logged

Florida
Offline Offline
God Member
*****
Karma: 2
Posts: 554
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you so much!!!!
Logged

Florida
Offline Offline
God Member
*****
Karma: 2
Posts: 554
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

One more question….

This will take up four analog inputs?


Thanks,
Drew Davis
Logged

Dubuque, Iowa, USA
Offline Offline
Edison Member
*
Karma: 29
Posts: 2244
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Just two pins. One U/D and one L/R.
Logged

Florida
Offline Offline
God Member
*****
Karma: 2
Posts: 554
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What i'm trying to achieve is to have one led blink faster when I push down and another LED blink faster when I push to the left.

It is not working and I don't know why. When I move my joy stick in one direction both lights change the frequency of their blinks. Other times they don't change at all. I'm completely lost.  Could somebody please tell me if it's my program or my wiring.

I wired both L/R's to A2 and both U/D's to A5

Here is my program….

const int ledPin =  13;
const int ledPin2 = 12; // the number of the LED pin

// Variables will change:
int ledState = LOW;
int ledState2 = LOW; // ledState used to set the LED
long previousMillis = 0;
long previousMillis2 = 0;// will store last time LED was updated
int time = 2;
int time2 = 5;
// the follow variables is a long because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long interval = 1000;           // interval at which to blink (milliseconds)
long interval2 = 100;

void setup() {
  // set the digital pin as output:
  pinMode(ledPin, OUTPUT);
pinMode(ledPin2, OUTPUT); 
}

void loop()
{
  // here is where you'd put code that needs to be running all the time.

  // check to see if it's time to blink the LED; that is, if the
  // difference between the current time and last time you blinked
  // the LED is bigger than the interval at which you want to
  // blink the LED.
 
 long interval = analogRead(time);
  long interval2 = analogRead(time2);
 
  unsigned long currentMillis = millis();
 
  if(currentMillis - previousMillis > interval) {
    // save the last time you blinked the LED
    previousMillis = currentMillis;   

    // if the LED is off turn it on and vice-versa:
    if (ledState == LOW)
      ledState = HIGH;
    else
      ledState = LOW;

    // set the LED with the ledState of the variable:
    digitalWrite(ledPin, ledState);
   
    //////////////////////////////////////////////////
   
    unsigned long currentMillis = millis();
 
  if(currentMillis - previousMillis2 > interval2) {
    // save the last time you blinked the LED
    previousMillis2 = currentMillis;   

    // if the LED is off turn it on and vice-versa:
    if (ledState2 == LOW)
      ledState2 = HIGH;
    else
      ledState2 = LOW;

    // set the LED with the ledState of the variable:
    digitalWrite(ledPin2, ledState2);
   
   
  }
  }
}

Thanks,
Drew Davis
Logged

Florida
Offline Offline
God Member
*****
Karma: 2
Posts: 554
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Any Suggestions?

Thanks,
Drew Davis
Logged

Pages: [1]   Go Up
Jump to: