Hi,
I'm trying to read the position of an Nintendo 64 controller's analog stick. It uses two optical encoders, one for the X and one for the Y direction.
For testing purposes, I am just attempting to read the X value for now and I've connected the analog sticks pin 1 and 4 which are the encoder outputs for the X axis on the N64 stick to pin 0 and pin 1 on the teensy.
I have the N64 controller plugged into the Nintendo so it is receiving power, and I have my Teensy 3.5 plugged in via USB.
My sketch (via arduino):
While running, if I move the analog stick in a direction count_x will generally change to a value of 1, and when I release it it goes back to 0, so something is being detected but it's not tracking the position correctly. This code is basically from a youtube video, and there is a blog of someone else using this code specifically for an N64 analog stick so I believe the issue is most likely elsewhere. I've very little electronics experience, coming from a programming background.
Kind regards,
Kaine
I'm trying to read the position of an Nintendo 64 controller's analog stick. It uses two optical encoders, one for the X and one for the Y direction.
For testing purposes, I am just attempting to read the X value for now and I've connected the analog sticks pin 1 and 4 which are the encoder outputs for the X axis on the N64 stick to pin 0 and pin 1 on the teensy.
I have the N64 controller plugged into the Nintendo so it is receiving power, and I have my Teensy 3.5 plugged in via USB.
My sketch (via arduino):
Code:
static int Ix = 0;
static int Qx = 1;
volatile int count_x = 0;
void setup() {
Serial.begin(9600);
pinMode(Ix, INPUT);
pinMode(Qx, INPUT);
attachInterrupt(0, detectX, CHANGE);
}
void loop() {
Serial.print("X: ");
Serial.println(count_x);
delay(10);
}
void detectX()
{
if(digitalRead(Ix) == digitalRead(Qx))
{
count_x++;
}
else
{
count_x--;
}
}
While running, if I move the analog stick in a direction count_x will generally change to a value of 1, and when I release it it goes back to 0, so something is being detected but it's not tracking the position correctly. This code is basically from a youtube video, and there is a blog of someone else using this code specifically for an N64 analog stick so I believe the issue is most likely elsewhere. I've very little electronics experience, coming from a programming background.
Kind regards,
Kaine