XIM Community

Teensy new Code from W11ce  (Read 1632 times)

Offline roads

  • MVP
  • *
  • Posts: 19071
    • View Profile
Teensy new Code from W11ce
« on: 04:19 AM - 10/18/16 »
W11ce always helpful gave me the new code for the Teensy if used without Commander directly on the XIM4. heres the Arduino code if you want to replace any Joystick or gaming Keyboard with the Teensy. You need to install arduino, Teensyduino and flash with mouse+keyboard+joystick option. Connect the wires and done.

Code: [Select]
int axelX;
int axelY;

int overVal = 128;

void setup()
{
  Joystick.useManualSend(true);
  //pinMode(0, INPUT_PULLUP);
  pinMode(1, INPUT_PULLUP);
  pinMode(2, INPUT_PULLUP);
  pinMode(3, INPUT_PULLUP);
  pinMode(4, INPUT_PULLUP);
  pinMode(5, INPUT_PULLUP);
  pinMode(6, INPUT_PULLUP);
  pinMode(7, INPUT_PULLUP);
  pinMode(8, INPUT_PULLUP);
  pinMode(9, INPUT_PULLUP);
  pinMode(10, INPUT_PULLUP);
  pinMode(11, INPUT_PULLUP);
  pinMode(12, INPUT_PULLUP);
  pinMode(13, INPUT_PULLUP);
  pinMode(16, INPUT_PULLUP);
  pinMode(17, INPUT_PULLUP);
  pinMode(18, INPUT_PULLUP);
  pinMode(19, INPUT_PULLUP);
  pinMode(20, INPUT_PULLUP);
  pinMode(21, INPUT_PULLUP);
  pinMode(22, INPUT_PULLUP);
  pinMode(23, INPUT_PULLUP);
  pinMode(24, INPUT_PULLUP);
  pinMode(25, INPUT_PULLUP);
  pinMode(26, INPUT_PULLUP);
  pinMode(27, INPUT_PULLUP);
  pinMode(28, INPUT_PULLUP);
}
void loop() {
 //Orbweaver Thumb-piece
    //Joystick.button(21, !digitalRead(0));
    Joystick.button(22, !digitalRead(1));
    Joystick.button(23, !digitalRead(2));
    Joystick.button(24, !digitalRead(3));
    Joystick.button(25, !digitalRead(4));
    Joystick.button(26, !digitalRead(5));

 // Keyboard
    Joystick.button(1, !digitalRead(6));
    Joystick.button(2, !digitalRead(7));
    Joystick.button(3, !digitalRead(8));
    Joystick.button(4, !digitalRead(9));
    Joystick.button(5, !digitalRead(10));
    Joystick.button(6, !digitalRead(11));
    Joystick.button(7, !digitalRead(12));
    Joystick.button(8, !digitalRead(16));
    Joystick.button(9, !digitalRead(17));
    Joystick.button(10, !digitalRead(18));
    Joystick.button(11, !digitalRead(19));
    Joystick.button(12, !digitalRead(20));
    Joystick.button(13, !digitalRead(21));
    Joystick.button(14, !digitalRead(22));
    Joystick.button(15, !digitalRead(23));
    Joystick.button(16, !digitalRead(24));
    Joystick.button(17, !digitalRead(25));
    Joystick.button(18, !digitalRead(26));
    Joystick.button(19, !digitalRead(27));
    Joystick.button(20, !digitalRead(28));


    //Joystick (pins 14 and 15)
    axelX = map(analogRead(0), 0, 1023, 1023+overVal, 0-overVal);
    axelX = constrain(axelX, 0, 1023);
    axelY = map(analogRead(1), 0, 1023, 1023+overVal, 0-overVal);
    axelY = constrain(axelY, 0, 1023);

    Joystick.X(axelX);
    Joystick.Y(axelY);

Joystick.Z(512);
Joystick.Zrotate(512);
Joystick.sliderLeft(0);
Joystick.sliderRight(0);
Joystick.hat(-1);

      //Touch buttons mouse
     if(touchRead(32) > 3000) Joystick.button(27, 1);
     else Joystick.button(27, 0);
     if(touchRead(33) > 3000) Joystick.button(28, 1);
     else Joystick.button(28, 0);
     //touch button Orbweaver
     if(touchRead(0) > 3000) Joystick.button(21, 1);
     else Joystick.button(21, 0);
     Joystick.send_now();
  //  delay (50);
}
RookCheck: Relax, no one is attacking you personally.

Offline tails72

  • MVP
  • *
  • Posts: 527
    • View Profile
Re: Teensy new Code from W11ce
« Reply #1 on: 08:24 AM - 10/18/16 »
so this could be used for thumbstick and some buttons?

I guess you would need to delete some lines of code though wouldn't you.

Will definatly try it on my project

Offline W11cE

  • MVP
  • *
  • Posts: 1222
    • View Profile
Re: Teensy new Code from W11ce
« Reply #2 on: 02:41 PM - 10/18/16 »
Was going to post this to the original thread, but roads was faster. So the main point is this part:
Code: [Select]
Joystick.Z(512);
Joystick.Zrotate(512);
Joystick.sliderLeft(0);
Joystick.sliderRight(0);
Joystick.hat(-1);

This will set all the other axes (right stick and triggers) to the resting position. Of course no need if you are using those in your mod, but previously we couldn't.

Offline ScopeLoc

  • Member
  • *
  • Posts: 102
    • View Profile
Re: Teensy new Code from W11ce
« Reply #3 on: 06:19 PM - 03/23/17 »
I haven't used mine for awhile. I did not realize there was an update. Thank you for taking the time to help others.

Offline drmeltdown

  • Member
  • *
  • Posts: 25
    • View Profile
Re: Teensy new Code from W11ce
« Reply #4 on: 05:57 PM - 04/04/17 »
What's being built with this? I'm planning to build a wii nunchuck mod (adding extra buttons) since its more ergonomic than the nav. I was planning to flash with mmjoy2 (info here: https://github.com/MMjoy/mmjoy_en/wiki )
Any advantage of using your code over something else such as mmjoy2?