1. Do not share user accounts! Any account that is shared by another person will be blocked and closed. This means: we will close not only the account that is shared, but also the main account of the user who uses another person's account. We have the ability to detect account sharing, so please do not try to cheat the system. This action will take place on 04/18/2023. Read all forum rules.
    Dismiss Notice
  2. For downloading SimTools plugins you need a Download Package. Get it with virtual coins that you receive for forum activity or Buy Download Package - We have a zero Spam tolerance so read our forum rules first.

    Buy Now a Download Plan!
  3. Do not try to cheat our system and do not post an unnecessary amount of useless posts only to earn credits here. We have a zero spam tolerance policy and this will cause a ban of your user account. Otherwise we wish you a pleasant stay here! Read the forum rules
  4. We have a few rules which you need to read and accept before posting anything here! Following these rules will keep the forum clean and your stay pleasant. Do not follow these rules can lead to permanent exclusion from this website: Read the forum rules.
    Are you a company? Read our company rules

DIY Arduino Buttonbox

Discussion in 'DIY peripherals' started by TOPMO3, Mar 28, 2016.

  1. Danilo Santos

    Danilo Santos New Member

    Joined:
    Jul 26, 2019
    Messages:
    4
    Balance:
    21Coins
    Ratings:
    +0 / 0 / -0
    My Motion Simulator:
    Arduino
    Is this code that AmStudio made of 32 buttons? You have modified to place the potentiometers
  2. JonBakhol

    JonBakhol Active Member

    Joined:
    Mar 16, 2018
    Messages:
    107
    Location:
    Netherlands harderwijk
    Balance:
    442Coins
    Ratings:
    +46 / 1 / -0
    My Motion Simulator:
    2DOF, DC motor, JRK
    Hi Danilo,

    I indeed modified the code for encoders and potmeter. In this case the potentiometer is on A10.

    Ride on
  3. Роман 2222

    Роман 2222 New Member

    Joined:
    Aug 22, 2019
    Messages:
    1
    Balance:
    78Coins
    Ratings:
    +0 / 0 / -0
    My Motion Simulator:
    Arduino
    привет)
    Я решил построить себе button box, потому что это очень интересно.
    Я прошу помощи у Вас. Я использую скетч. Я разобрался как подключать кнопки и энкодеры. Но в чем проблема, а в том что мне нужно как-то сделать так, чтобы Ардуинка воспринимала всегда нажатий тумблер как одно нажатия кнопки. Но тумблера это ещё половина "головной боли", а ещё с замком зажигания. Я разобрался как его подключать, но такая же проблема как и с тумблерами. У замка есть 2 положения: 1) зажигания (он всегда зажатой, имею в виду, что кнопка всегда ON)
    2) стартер (там все нормально, потому что ключ сам возвращается)
    И нужно как-то сделать так, чтобы зажигания работало ON - OFF.
    Надеюсь, что нормально объяснил, что мне нужно.
    Заранее огромное спасибо!
  4. noorbeast

    noorbeast VR Tassie Devil Staff Member Moderator Race Director

    Joined:
    Jul 13, 2014
    Messages:
    21,097
    Occupation:
    Innovative tech specialist for NGOs
    Location:
    St Helens, Tasmania, Australia
    Balance:
    148,264Coins
    Ratings:
    +10,893 / 54 / -2
    My Motion Simulator:
    3DOF, DC motor, JRK
    Please be aware that you can dual language post but it is part of the Forum Rules that you also include English, doing so via Google Translate is fine: https://www.xsimulator.net/community/threads/forum-rules.9527/
  5. Danilo Santos

    Danilo Santos New Member

    Joined:
    Jul 26, 2019
    Messages:
    4
    Balance:
    21Coins
    Ratings:
    +0 / 0 / -0
    My Motion Simulator:
    Arduino
    Could friend help me? I use a micro arduino and I have a buttonbox with 10 Momentary buttons like yours, 3 fixed position on / off switch (marked in red) and 2 on / off switch on the G27's shift knob (marked in red) and 4 more Micro switch for arrow key. all turned on in Arduino Micro. My problem is with the fixed position switches mainly the 2 of the G27's shift knob, when the two G27 handle switches are activated, other buttons in the buttonbox or arrow key conflict. How can I solve this? each button fixed in a row?
    IMG_20190901_170635.jpg
  6. Danilo Santos

    Danilo Santos New Member

    Joined:
    Jul 26, 2019
    Messages:
    4
    Balance:
    21Coins
    Ratings:
    +0 / 0 / -0
    My Motion Simulator:
    Arduino
    images (11).jpeg
    Buddy I use an Arduino Pro Micro where I connect the 3 potentiometer pins? And another thing when I compiled your programming, my computer mouse got out of control and the arduino became a mouse.
  7. JonBakhol

    JonBakhol Active Member

    Joined:
    Mar 16, 2018
    Messages:
    107
    Location:
    Netherlands harderwijk
    Balance:
    442Coins
    Ratings:
    +46 / 1 / -0
    My Motion Simulator:
    2DOF, DC motor, JRK
    He Danilo,

    The Potentiometer will come on Ground, 5 Volt (VCC) and A10.
    Indeed, There is a mouse also in the sketch. I put a joystick in the steering wheel for controlling the menu in Assetto Corsa.
    Last edited: Sep 5, 2019
  8. evolaco

    evolaco Member

    Joined:
    Sep 27, 2015
    Messages:
    260
    Location:
    Spain
    Balance:
    1,070Coins
    Ratings:
    +29 / 0 / -0
    My Motion Simulator:
    3DOF
  9. Mattx38

    Mattx38 New Member

    Joined:
    Oct 9, 2019
    Messages:
    3
    Balance:
    32Coins
    Ratings:
    +0 / 0 / -0
    My Motion Simulator:
    Arduino
    Hello, Very nice project. I'm wondering to make the same kind of button box for SimRacing. Could someone explain me how the Arduino knows which button is pushed on the line of 5 buttons ?
    Thank you
  10. noorbeast

    noorbeast VR Tassie Devil Staff Member Moderator Race Director

    Joined:
    Jul 13, 2014
    Messages:
    21,097
    Occupation:
    Innovative tech specialist for NGOs
    Location:
    St Helens, Tasmania, Australia
    Balance:
    148,264Coins
    Ratings:
    +10,893 / 54 / -2
    My Motion Simulator:
    3DOF, DC motor, JRK
    Have a look at the first post in thew thread covering the Teensy and code: https://www.xsimulator.net/community/threads/diy-arduino-buttonbox.8302/
  11. Mattx38

    Mattx38 New Member

    Joined:
    Oct 9, 2019
    Messages:
    3
    Balance:
    32Coins
    Ratings:
    +0 / 0 / -0
    My Motion Simulator:
    Arduino
    I understood the matrix behavior.
    I think I have too many buttons and switch in my project.

    I have :
    • 7x momentary push buttons (on/off) = 14 positions
    • 3x rotary encoders with momentary push button = 6 positions & neutral + 6 positions
    • 3x momentary toggle switch on/off/on (3 pins) = 9 positions
    • 3x toggle switch on/off/on (3 pins) = 9 positions
    • 3x toggle switch on/on (3 pins) = 9 positions
    So I have to make a matrix for 14 + 6 + 3x 9 = 50 positions, so I need 7 col x 8 lines = 15 inputs
    + 6 inputs for therotary encoders

    There is not enought inputs on the Arduino Micro ; even on a Uno.
  12. Oz_gadget

    Oz_gadget New Member

    Joined:
    Oct 18, 2019
    Messages:
    16
    Occupation:
    retired
    Location:
    Melbourne, Australia
    Balance:
    243Coins
    Ratings:
    +4 / 0 / -0
    My Motion Simulator:
    Arduino, Joyrider, Motion platform, 6DOF
    G'day Gentlemen
    I've been looking around this site in awe & with some trepidation, as I am keen to build a 6DoF platform but not sure where to start, still working out what I need to know and most importantly learning what I didn't know I needed to know.... :blush

    I came across this thread and thought I might be able to contribute something
    for those of you who are not as electronically savvy or arduino coders.... (as I am not on both accounts)
    you may find this simple solution effective for DIY button boxes

    I am a flight sim enthusiast, not a racer, but a button box is a button box.

    https://avimator.net/229wiki/index.php?title=Shift_Register

    Rather than trying to work out a switch matrix, try using a shift register.
    It will allow you to increase your button/switch count exponentially without additional pin consumption of the controller board. In this case a arduino clone pro-micro

    @Mattx38 this solution would allow you to use a simple arduino mini and only need 5 pins.
    all the inputs to the switches run from the shift register (up to 32) and increase by dasiy-chaining more shift registers via the same 5 pins only.

    https://www.aliexpress.com/item/32818968146.html

    They are readily available from such sites as AliExpress, and cheap as chips.

    https://www.aliexpress.com/item/32861811972.html?spm=2114.12010612/itm2home-1.0.0.6e4c7e80QWiob1

    You can flash the firmware using MMJoy2 and then have a handy interface for configuring your controller.
    https://github.com/MMjoy/mmjoy_en/wiki

    Please Note: the pins labels may differ in the MMJoy2 interface to whatever is written on the PCB

    Attached Files:

    Last edited: Nov 15, 2019
  13. Eien

    Eien New Member

    Joined:
    Nov 14, 2019
    Messages:
    2
    Balance:
    76Coins
    Ratings:
    +0 / 0 / -0
    My Motion Simulator:
    Arduino
    Hello guys. I need help. Im usin this code:

    Code:
    #include <Keypad.h>
    #include <Joystick.h>
    
    
    #define ENABLE_PULLUPS
    #define NUMROTARIES 4
    #define NUMBUTTONS 25
    #define NUMROWS 5
    #define NUMCOLS 5
    
    
    //define the symbols on the buttons of the keypads
    byte buttons[NUMROWS][NUMCOLS] = {
      {1,2,3,4,5},
      {6,7,8,9,10},
      {11,12,13,14,15},
      {16,17,18,19,20},
      {21,22,23,24,25},
    };
    
    
    
    struct rotariesdef {
      byte pin1;
      byte pin2;
      int ccwchar;
      int cwchar;
      volatile unsigned char state;
    };
    
    rotariesdef rotaries[NUMROTARIES] {
      {0,1,26,27,0},
      {2,3,28,29,0},
      {4,5,30,31,0},
      {6,7,32,33,0},
    };
    
    
    
    #define DIR_CCW 0x10
    #define DIR_CW 0x20
    
    #define R_START 0x0
    #define R_CW_FINAL 0x1
    #define R_CW_BEGIN 0x2
    #define R_CW_NEXT 0x3
    #define R_CCW_BEGIN 0x4
    #define R_CCW_FINAL 0x5
    #define R_CCW_NEXT 0x6
    
    const unsigned char ttable[7][4] = {
      // R_START
      {R_START,    R_CW_BEGIN,  R_CCW_BEGIN, R_START},
      // R_CW_FINAL
      {R_CW_NEXT,  R_START,     R_CW_FINAL,  R_START | DIR_CW},
      // R_CW_BEGIN
      {R_CW_NEXT,  R_CW_BEGIN,  R_START,     R_START},
      // R_CW_NEXT
      {R_CW_NEXT,  R_CW_BEGIN,  R_CW_FINAL,  R_START},
      // R_CCW_BEGIN
      {R_CCW_NEXT, R_START,     R_CCW_BEGIN, R_START},
      // R_CCW_FINAL
      {R_CCW_NEXT, R_CCW_FINAL, R_START,     R_START | DIR_CCW},
      // R_CCW_NEXT
      {R_CCW_NEXT, R_CCW_FINAL, R_CCW_BEGIN, R_START},
    };
    
    
    byte rowPins[NUMROWS] = {21,20,19,18,15}; //connect to the row pinouts of the keypad
    byte colPins[NUMCOLS] = {14,16,10,9,8}; //connect to the column pinouts of the keypad
    
    //initialize an instance of class NewKeypad
    Keypad buttbx = Keypad( makeKeymap(buttons), rowPins, colPins, NUMROWS, NUMCOLS);
    
    
    
    void setup() {
      Joystick.begin();
      rotary_init();
    }
    
    
    
    void loop() {
    
      CheckAllEncoders();
    
      CheckAllButtons();
    
    }
    
    
    void CheckAllButtons(void) {
          if (buttbx.getKeys())
        {
           for (int i=0; i<LIST_MAX; i++)   // Scan the whole key list.
            {
                switch (buttbx.key[i].kstate) {  // Report active key state : IDLE, PRESSED, HOLD, or RELEASED
                        case PRESSED:
                        case HOLD:
                                  Joystick.setButton(buttbx.key[i].kchar, 1);
                                  break;
                        case RELEASED:
                        case IDLE:
                                  Joystick.setButton(buttbx.key[i].kchar, 0);
                                  break;
                }
                   
             }
         }
    }
    
    
    /* Call this once in setup(). */
    void rotary_init() {
      for (int i=0;i<NUMROTARIES;i++) {
        pinMode(rotaries[i].pin1, INPUT);
        pinMode(rotaries[i].pin2, INPUT);
        #ifdef ENABLE_PULLUPS
          digitalWrite(rotaries[i].pin1, HIGH);
          digitalWrite(rotaries[i].pin2, HIGH);
        #endif
      }
    }
    
    
    /* Read input pins and process for events. Call this either from a
     * loop or an interrupt (eg pin change or timer).
     *
     * Returns 0 on no event, otherwise 0x80 or 0x40 depending on the direction.
     */
    unsigned char rotary_process(int _i) {
       unsigned char pinstate = (digitalRead(rotaries[_i].pin2) << 1) | digitalRead(rotaries[_i].pin1);
      rotaries[_i].state = ttable[rotaries[_i].state & 0xf][pinstate];
      return (rotaries[_i].state & 0x30);
    }
    
    void CheckAllEncoders(void) {
      for (int i=0;i<NUMROTARIES;i++) {
        unsigned char result = rotary_process(i);
        if (result == DIR_CCW) {
          Joystick.setButton(rotaries[i].ccwchar, 1); delay(50); Joystick.setButton(rotaries[i].ccwchar, 0);
        };
        if (result == DIR_CW) {
          Joystick.setButton(rotaries[i].cwchar, 1); delay(50); Joystick.setButton(rotaries[i].cwchar, 0);
        };
      }
    }
    I want to use this 3 way sw. like this : https://ru.aliexpress.com/item/477147479.html . What changes should I make to the Code? Im new.
  14. Mattx38

    Mattx38 New Member

    Joined:
    Oct 9, 2019
    Messages:
    3
    Balance:
    32Coins
    Ratings:
    +0 / 0 / -0
    My Motion Simulator:
    Arduino
    Thank you Oz_gadget.
    It is pretty interesting. I would try it when I give up with the Arduino sketch ;-)

    If anyone can explain me how to adapt the code to my button box.
  15. Eien

    Eien New Member

    Joined:
    Nov 14, 2019
    Messages:
    2
    Balance:
    76Coins
    Ratings:
    +0 / 0 / -0
    My Motion Simulator:
    Arduino
  16. quakebo

    quakebo New Member

    Joined:
    Dec 10, 2019
    Messages:
    1
    Balance:
    107Coins
    Ratings:
    +0 / 0 / -0
    I have built this and use it on my xbox one in pc2 it works good but it sees key presses as a letter and not LEFT_CTRL + LEFT_ALT the letter. Why is this?

    As I use a another button box I made using a different keyboard encoder that uses only one key and not three for button presses so I thought there would not be a problem. But on this one using Arduino Pro Micro on xbox one I think jt just sees it as one key press and not three.
  17. reddo

    reddo New Member

    Joined:
    Nov 18, 2017
    Messages:
    13
    Location:
    Nederland
    Balance:
    267Coins
    Ratings:
    +10 / 1 / -0
    Happy 2020 to all first.

    Then, with the button box, 6 buttons all give the same 'ctrl' input in raceroom.. Any idea what cuases this ?

    Cheers.

    Edit: Solved, uploaded the joystick version, now all OK. Perfect !! Got a button box on my wheel (see earlier post) mated to a T300 base.
    Last edited: Jan 4, 2020
  18. mkydj

    mkydj New Member

    Joined:
    Jan 5, 2020
    Messages:
    2
    Balance:
    50Coins
    Ratings:
    +0 / 0 / -0
    Hi,
    I have changed the code to use one encoder for 3 cnc axis, inserted a button to select the axis with LED, the only thing is not being able to select the code, example:

    rotariesdef rotaries [NUMROTARIES] {
    for x axis {6,7, KEY_RIGHT_ARROW, KEY_LEFT_ARROW, 0},
    for y axis {6,7, KEY_DOWN_ARROW, KEY_UP_ARROW, 0},
    for z axis {6,7, KEY_PAGE_UP, KEY_PAGE_DOWN, 0},
    };

    complete code:

    #include <Keypad.h>
    #include <Keyboard.h>


    #define ENABLE_PULLUPS
    #define NUMROTARIES 1
    #define NUMBUTTONS 25
    #define NUMROWS 5
    #define NUMCOLS 5




    // define the symbols on the buttons of the keypads
    char buttons [NUMROWS] [NUMCOLS] = {
    { 'Q', 'w', 'e', 'r', 't'},
    { 'Y', 'u', 'i', 'o', 'p'},
    { 'A', 's', 'd', 'f', 'g'},
    { 'H', 'j', 'k', 'l', 'z'},
    { 'X', 'c', 'v', 'b', 'n'},
    };





    struct rotariesdef {
    byte pin1;
    byte pin2;
    int ccwchar;
    int cwchar;
    volatile unsigned char state;
    };

    -------------------------------------------------- -------------------------------
    rotariesdef rotaries [NUMROTARIES] {
    {6,7, KEY_RIGHT_ARROW, KEY_LEFT_ARROW, 0},
    {6,7, KEY_DOWN_ARROW, KEY_UP_ARROW, 0},
    {6,7, KEY_PAGE_UP, KEY_PAGE_DOWN, 0},
    };
    -------------------------------------------------- ------------------------------



    //
    // Encoders code from Ben Buxton
    // More info: http://www.buxtronix.net/2011/10/rotary-encoders-done-properly.html
    //

    #define DIR_CCW 0x10
    #define DIR_CW 0x20

    #define R_START 0x0
    #define R_CW_FINAL 0x1
    #define R_CW_BEGIN 0x2
    #define R_CW_NEXT 0x3
    #define R_CCW_BEGIN 0x4
    #define R_CCW_FINAL 0x5
    #define R_CCW_NEXT 0x6



    const unsigned char ttable [7] [4] = {
    // R_START
    {R_START, R_CW_BEGIN, R_CCW_BEGIN, R_START},
    // R_CW_FINAL
    {R_CW_NEXT, R_START, R_CW_FINAL, R_START | DIR_CW},
    // R_CW_BEGIN
    {R_CW_NEXT, R_CW_BEGIN, R_START, R_START},
    // R_CW_NEXT
    {R_CW_NEXT, R_CW_BEGIN, R_CW_FINAL, R_START},
    // R_CCW_BEGIN
    {R_CCW_NEXT, R_START, R_CCW_BEGIN, R_START},
    // R_CCW_FINAL
    {R_CCW_NEXT, R_CCW_FINAL, R_START, R_START | DIR_CCW},
    // R_CCW_NEXT
    {R_CCW_NEXT, R_CCW_FINAL, R_CCW_BEGIN, R_START},
    };

    int ledx = 2;
    int ledy = 3;
    int ledz = 4;
    int but = 5;
    int but_t = 0;
    int lastButtonState = 1;
    int axis = 0;

    byte rowPins [NUMROWS] = {21,20,19,18,15}; // connect to the row pinouts of the keypad
    byte colPins [NUMCOLS] = {14,16,10,9,8}; // connect to the column pinouts of the keypad

    // initialize an instance of class NewKeypad
    Keypad buttbx = Keypad (makeKeymap (buttons), rowPins, colPins, NUMROWS, NUMCOLS);



    void setup () {
    Keyboard.begin ();
    rotary_init ();
    pinMode (ledx, OUTPUT);
    pinMode (ledy, OUTPUT);
    pinMode (ledz, OUTPUT);
    pinMode (but, INPUT_PULLUP);
    }



    void loop () {

    CheckAllEncoders ();

    but_t = digitalRead (but);


    if (but_t! = lastButtonState) {

    if (but_t == HIGH) {
    axis ++;
    if (axis == 4) {
    axis = 0;
    digitalWrite (ledz, LOW);
    }
    }
    delay (50);
    }

    if (axis == 1) {
    digitalWrite (ledz, LOW);
    digitalWrite (ledx, HIGH);
    }



    if (axis == 2) {
    digitalWrite (ledx, LOW);
    digitalWrite (ledy, HIGH);
    }


    if (axis == 3) {
    digitalWrite (ledy, LOW);
    digitalWrite (ledz, HIGH);
    }


    lastButtonState = but_t;



    CheckAllButtons ();

    }



    void CheckAllButtons (void) {
    char key = buttbx.getKey ();
    if (key! = NO_KEY) {
    Keyboard.press (KEY_LEFT_CTRL);
    Keyboard.press (KEY_LEFT_ALT);
    Keyboard.press (key);
    delay (150);
    Keyboard.releaseAll ();
    }
    }


    / * Call this once in setup (). * /
    void rotary_init () {
    for (int i = 0; i <NUMROTARIES; i ++) {
    pinMode (rotaries .pin1, INPUT);
    pinMode (rotaries .pin2, INPUT);
    #ifdef ENABLE_PULLUPS
    digitalWrite (rotaries .pin1, HIGH);
    digitalWrite (rotaries .pin2, HIGH);
    #endif
    }
    }


    / * Read input pins and process for events. Call this either from a
    * loop or an interrupt (eg pin change or timer).
    *
    * Returns 0 on no event, otherwise 0x80 or 0x40 depending on the direction.
    * /
    unsigned char rotary_process (int _i) {
    unsigned char pinstate = (digitalRead (rotaries [_i] .pin2) << 1) | digitalRead (rotaries [_i] .pin1);
    rotaries [_i] .state = ttable [rotaries [_i] .state & 0xf] [pinstate];
    return (rotaries [_i] .state & 0x30);
    }


    void CheckAllEncoders (void) {
    for (int i = 0; i <NUMROTARIES; i ++) {
    unsigned char result = rotary_process (i);
    if (result) {
    Keyboard.write (result == DIR_CCW? Rotaries .ccwchar: rotaries .cwchar);
    }
    }
    }

    Attached Files:

  19. mkydj

    mkydj New Member

    Joined:
    Jan 5, 2020
    Messages:
    2
    Balance:
    50Coins
    Ratings:
    +0 / 0 / -0
    Solved problem insert switch selection axis.
    Code:

    #include <Keypad.h>
    #include <Keyboard.h>


    #define ENABLE_PULLUPS
    #define NUMROTARIES 3
    #define NUMBUTTONS 25
    #define NUMROWS 5
    #define NUMCOLS 5




    //define the symbols on the buttons of the keypads
    char buttons[NUMROWS][NUMCOLS] = {
    {'q','w','e','r','t'},
    {'y','u','i','o','p'},
    {'a','s','d','f','g'},
    {'h','j','k','l','z'},
    {'x','c','v','b','n'},
    };




    int avant;
    int indi;

    struct rotariesdef {
    byte pin1;
    byte pin2;
    int forword;
    int rewind;
    int up;
    int down;
    int left;
    int right;
    volatile unsigned char state;
    };


    rotariesdef rotaries[NUMROTARIES] {
    {6,7,KEY_UP_ARROW,KEY_DOWN_ARROW,KEY_LEFT_ARROW,KEY_RIGHT_ARROW,KEY_PAGE_UP,KEY_PAGE_DOWN}
    };




    //
    //Encoders code from Ben Buxton
    //More info: http://www.buxtronix.net/2011/10/rotary-encoders-done-properly.html
    //

    #define DIR_CCW 0x10
    #define DIR_CW 0x20

    #define R_START 0x0
    #define R_CW_FINAL 0x1
    #define R_CW_BEGIN 0x2
    #define R_CW_NEXT 0x3
    #define R_CCW_BEGIN 0x4
    #define R_CCW_FINAL 0x5
    #define R_CCW_NEXT 0x6



    const unsigned char ttable[7][4] = {
    // R_START
    {R_START, R_CW_BEGIN, R_CCW_BEGIN, R_START},
    // R_CW_FINAL
    {R_CW_NEXT, R_START, R_CW_FINAL, R_START | DIR_CW},
    // R_CW_BEGIN
    {R_CW_NEXT, R_CW_BEGIN, R_START, R_START},
    // R_CW_NEXT
    {R_CW_NEXT, R_CW_BEGIN, R_CW_FINAL, R_START},
    // R_CCW_BEGIN
    {R_CCW_NEXT, R_START, R_CCW_BEGIN, R_START},
    // R_CCW_FINAL
    {R_CCW_NEXT, R_CCW_FINAL, R_START, R_START | DIR_CCW},
    // R_CCW_NEXT
    {R_CCW_NEXT, R_CCW_FINAL, R_CCW_BEGIN, R_START},
    };

    int ledx = 2;
    int ledy = 3;
    int ledz = 4;
    int but = 5;
    int but_t = 0;
    int lastButtonState = 1;
    int axis = 0;


    byte rowPins[NUMROWS] = {21,20,19,18,15}; //connect to the row pinouts of the keypad
    byte colPins[NUMCOLS] = {14,16,10,9,8}; //connect to the column pinouts of the keypad

    //initialize an instance of class NewKeypad
    Keypad buttbx = Keypad( makeKeymap(buttons), rowPins, colPins, NUMROWS, NUMCOLS);



    void setup() {
    Keyboard.begin();
    rotary_init();
    pinMode(ledx, OUTPUT);
    pinMode(ledy, OUTPUT);
    pinMode(ledz, OUTPUT);
    pinMode(but, INPUT_PULLUP );
    }



    void loop() {


    CheckAllEncoders();{
    but_t = digitalRead(but);


    if (but_t != lastButtonState) {

    if (but_t == HIGH) {
    axis++;
    if (axis == 4){
    axis = 0;
    digitalWrite(ledz, LOW);
    }
    }
    delay(50);
    }

    if (axis == 1) {
    digitalWrite(ledz, LOW);
    digitalWrite(ledx, HIGH);
    }



    if (axis == 2) {
    digitalWrite(ledx, LOW);
    digitalWrite(ledy, HIGH);
    }


    if (axis == 3) {
    digitalWrite(ledy, LOW);
    digitalWrite(ledz, HIGH);
    }


    lastButtonState = but_t;

    }

    CheckAllButtons();



    }



    void CheckAllButtons(void) {
    char key = buttbx.getKey();
    if (key != NO_KEY) {

    Keyboard.press(KEY_LEFT_ALT);
    Keyboard.press(key);
    delay(150);
    Keyboard.releaseAll();
    }
    }


    /* Call this once in setup(). */
    void rotary_init() {
    for (int i=0;i<NUMROTARIES;i++) {
    pinMode(rotaries.pin1, INPUT);
    pinMode(rotaries.pin2, INPUT);
    #ifdef ENABLE_PULLUPS
    digitalWrite(rotaries.pin1, HIGH);
    digitalWrite(rotaries.pin2, HIGH);
    #endif
    }
    }


    /* Read input pins and process for events. Call this either from a
    * loop or an interrupt (eg pin change or timer).
    *
    * Returns 0 on no event, otherwise 0x80 or 0x40 depending on the direction.
    */
    unsigned char rotary_process(int _i) {
    unsigned char pinstate = (digitalRead(rotaries[_i].pin2) << 1) | digitalRead(rotaries[_i].pin1);
    rotaries[_i].state = ttable[rotaries[_i].state & 0xf][pinstate];
    return (rotaries[_i].state & 0x30);
    }


    void CheckAllEncoders(void) {
    if (axis == 1){
    for (int i=0;i<NUMROTARIES;i++) {
    unsigned char result = rotary_process(i);
    if (result) {
    Keyboard.write(result == DIR_CCW ? rotaries.down: rotaries.up);
    }
    }
    }
    if (axis == 2){
    for (int i=0;i<NUMROTARIES;i++) {
    unsigned char result = rotary_process(i);
    if (result) {
    Keyboard.write(result == DIR_CCW ? rotaries.forword: rotaries.rewind);
    }
    }
    }
    if (axis == 3){
    for (int i=0;i<NUMROTARIES;i++) {
    unsigned char result = rotary_process(i);
    if (result) {
    Keyboard.write(result == DIR_CCW ? rotaries.right: rotaries.left);
    }
    }
    }
    }

    Attached Files:

  20. Oz_gadget

    Oz_gadget New Member

    Joined:
    Oct 18, 2019
    Messages:
    16
    Occupation:
    retired
    Location:
    Melbourne, Australia
    Balance:
    243Coins
    Ratings:
    +4 / 0 / -0
    My Motion Simulator:
    Arduino, Joyrider, Motion platform, 6DOF
    G'day again guys
    thought I'd update with something I've been tinkering with, with a couple of my flight sim cohorts...
    https://forums.mudspike.com/t/mmjoy-pcb-design/9705

    This board has been designed to simplify the creation and connectivity for novice electronics users.
    hence some of the flexibility has been removed from a standard pro-micro/arduino clone/teensy board
    however it works with MMjoy2 & we hope will allow for many users, whom might have previously borked at their first attempt
    to potentially return and have another go at making their own peripherals.

    cheers

    Attached Files:

    • Like Like x 1
    • Winner Winner x 1
    Last edited: Feb 14, 2020