Teensy 3.2 trouble

Want to show off your own project? Want to keep a build log of it? Post it here!
Post Reply
Purple_Moogle_00
Posts: 13
Joined: Mon Nov 21, 2016 11:59 am
Has thanked: 7 times

Teensy 3.2 trouble

Post by Purple_Moogle_00 » Mon Dec 26, 2016 3:51 pm

Hi guys, I'm having a spot of trouble with the teensy code. Im using the example one from arduino 1.6.13 and teensyduino

here is the code

Code: Select all

/* Complete USB Joystick Example
   Teensy becomes a USB joystick with 16 or 32 buttons and 6 axis input

   You must select Joystick from the "Tools > USB Type" menu

   Pushbuttons should be connected between the digital pins and ground.
   Potentiometers should be connected to analog inputs 0 to 5.

   This example code is in the public domain.
*/

// Configure the number of buttons.  Be careful not
// to use a pin for both a digital button and analog
// axis.  The pullup resistor will interfere with
// the analog voltage.
const int numButtons = 16;  // 16 for Teensy, 32 for Teensy++

void setup() {
  // you can print to the serial monitor while the joystick is active!
  Serial.begin(9600);
  // configure the joystick to manual send mode.  This gives precise
  // control over when the computer receives updates, but it does
  // require you to manually call Joystick.send_now().
  Joystick.useManualSend(true);
  for (int i=0; i<numButtons; i++) {
    pinMode(i, INPUT_PULLUP);
  }
  Serial.println("Begin Complete Joystick Test");
}

byte allButtons[numButtons];
byte prevButtons[numButtons];
int angle=0;

void loop() {
  // read 6 analog inputs and use them for the joystick axis
  Joystick.X(analogRead(0));
  Joystick.Y(analogRead(1));
  Joystick.Z(analogRead(2));
  Joystick.Zrotate(analogRead(3));
  Joystick.sliderLeft(analogRead(4));
  Joystick.sliderRight(analogRead(5));
  
  // read digital pins and use them for the buttons
  for (int i=0; i<numButtons; i++) {
    if (digitalRead(i)) {
      // when a pin reads high, the button is not pressed
      // the pullup resistor creates the "on" signal
      allButtons[i] = 0;
    } else {
      // when a pin reads low, the button is connecting to ground.
      allButtons[i] = 1;
    }
    Joystick.button(i + 1, allButtons[i]);
  }

  // make the hat switch automatically move in a circle
  angle = angle + 1;
  if (angle >= 360) angle = 0;
  Joystick.hat(angle);
  
  // Because setup configured the Joystick manual send,
  // the computer does not see any of the changes yet.
  // This send_now() transmits everything all at once.
  Joystick.send_now();
  
  // check to see if any button changed since last time
  boolean anyChange = false;
  for (int i=0; i<numButtons; i++) {
    if (allButtons[i] != prevButtons[i]) anyChange = true;
    prevButtons[i] = allButtons[i];
  }
  
  // if any button changed, print them to the serial monitor
  if (anyChange) {
    Serial.print("Buttons: ");
    for (int i=0; i<numButtons; i++) {
      Serial.print(allButtons[i], DEC);
    }
    Serial.println();
  }
  
  // a brief delay, so this runs "only" 200 times per second
  delay(5);
}
and here is the error message I recieve when trying to verify

Code: Select all

Arduino: 1.6.13 (Windows 10), TD: 1.33, Board: "Arduino/Genuino Uno"

C:\Program Files (x86)\Arduino\examples\Teensy\USB_Joystick\Complete\Complete.pde: In function 'void setup()':

Complete:24: error: 'Joystick' was not declared in this scope

   Joystick.useManualSend(true);

   ^

C:\Program Files (x86)\Arduino\examples\Teensy\USB_Joystick\Complete\Complete.pde: In function 'void loop()':

Complete:37: error: 'Joystick' was not declared in this scope

   Joystick.X(analogRead(0));

   ^

exit status 1
'Joystick' was not declared in this scope

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

User avatar
Camble
Posts: 885
Joined: Thu May 05, 2016 2:31 am
Location: Scotland
Has thanked: 269 times
Been thanked: 488 times

Re: Teensy 3.2 trouble

Post by Camble » Tue Dec 27, 2016 4:50 am

From the Arduino IDE Tools menu, make sure you choose Teensy 3.2 from "Board:" and under "USB Type:" choose an option which includes joystick.

Purple_Moogle_00
Posts: 13
Joined: Mon Nov 21, 2016 11:59 am
Has thanked: 7 times

Re: Teensy 3.2 trouble

Post by Purple_Moogle_00 » Tue Dec 27, 2016 3:39 pm

Camble wrote:From the Arduino IDE Tools menu, make sure you choose Teensy 3.2 from "Board:" and under "USB Type:" choose an option which includes joystick.
I have done as you said, make sure it is set to teensy 3.2 and make sure I use a usb joystick type. Do you think which one I pick matters? I clicked 'all of the above'? The problem is though when I click on joy.cpl I get random values. It thinks I'm pressing button 14 and that all the joysticks are moving even though I have not even soldered anything to it.
Screenshot (1).png
Screenshot (1).png (121 KiB) Viewed 5451 times
EDIT: I have changed the USB type to flight sim + joystick and it has not changed anything. The above problems still occur

User avatar
Camble
Posts: 885
Joined: Thu May 05, 2016 2:31 am
Location: Scotland
Has thanked: 269 times
Been thanked: 488 times

Re: Teensy 3.2 trouble

Post by Camble » Tue Dec 27, 2016 4:03 pm

Sounds about right. The unconnected axes will be moving because the pins are floating.

Purple_Moogle_00
Posts: 13
Joined: Mon Nov 21, 2016 11:59 am
Has thanked: 7 times

Re: Teensy 3.2 trouble

Post by Purple_Moogle_00 » Tue Dec 27, 2016 4:47 pm

Camble wrote:Sounds about right. The unconnected axes will be moving because the pins are floating.
Thank you for this. I thought something was seriously wrong

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest