Boutton box

hello I would like to do a programming of a box button to play dcs but I can't . I have 10 push button 7 switch on-off 2 switch on-off- (on), 3 switch (on) -off- (on) and 2 rotary encoder. I have a uno card. can you help me ?

Start plotting how and where to place the buttons in an ergonomic way. There are topics giving advice about reading buttons. Read that advice.

my button box is already done I still have the programming I just made all the videos on youtube none works

Show the code You have done so faar, using code tags please.

//BUTTON BOX
//USE w ProMicro
//Tested in WIN10 + Assetto Corsa
//AMSTUDIO
//20.8.17

#include <Keypad.h>
#include <Joystick.h>

#define ENABLE_PULLUPS
#define NUMROTARIES 4
#define NUMBUTTONS 24
#define NUMROWS 5
#define NUMCOLS 5

byte buttons[NUMROWS][NUMCOLS] = {
{0,1,2,3,4},
{5,6,7,8,9},
{10,11,12,13,14},
{15,16,17,18,19},
{20,21,22,23},
};

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

rotariesdef rotaries[NUMROTARIES] {
{0,1,24,25,0},
{2,3,26,27,0},
{4,5,28,29,0},
{6,7,30,31,0},
};

#define DIR_CCW 0x10
#define DIR_CW 0x20
#define R_START 0x0

#ifdef HALF_STEP
#define R_CCW_BEGIN 0x1
#define R_CW_BEGIN 0x2
#define R_START_M 0x3
#define R_CW_BEGIN_M 0x4
#define R_CCW_BEGIN_M 0x5
const unsigned char ttable[6][4] = {
// R_START (00)
{R_START_M, R_CW_BEGIN, R_CCW_BEGIN, R_START},
// R_CCW_BEGIN
{R_START_M | DIR_CCW, R_START, R_CCW_BEGIN, R_START},
// R_CW_BEGIN
{R_START_M | DIR_CW, R_CW_BEGIN, R_START, R_START},
// R_START_M (11)
{R_START_M, R_CCW_BEGIN_M, R_CW_BEGIN_M, R_START},
// R_CW_BEGIN_M
{R_START_M, R_START_M, R_CW_BEGIN_M, R_START | DIR_CW},
// R_CCW_BEGIN_M
{R_START_M, R_CCW_BEGIN_M, R_START_M, R_START | DIR_CCW},
};
#else
#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},
};
#endif

byte rowPins[NUMROWS] = {21,20,19,18,15};
byte colPins[NUMCOLS] = {14,16,10,9,8};

Keypad buttbx = Keypad( makeKeymap(buttons), rowPins, colPins, NUMROWS, NUMCOLS);

Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID,
JOYSTICK_TYPE_JOYSTICK, 32, 0,
false, false, false, false, false, false,
false, false, false, false, false);

void setup() {
Joystick.begin();
rotary_init();}

void loop() {

CheckAllEncoders();

CheckAllButtons();

}

void CheckAllButtons(void) {
if (buttbx.getKeys())
{
for (int i=0; i<LIST_MAX; i++)
{
if ( buttbx.key*.stateChanged ) *

  • {*
    _ switch (buttbx.key*.kstate) { _
    _
    case PRESSED:_
    _
    case HOLD:_
    _ Joystick.setButton(buttbx.key.kchar, 1);
    break;
    case RELEASED:
    case IDLE:
    Joystick.setButton(buttbx.key.kchar, 0);
    break;
    }
    }
    }
    }
    }
    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*

    * }
    }_

    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_.ccwchar, 1); delay(50); Joystick.setButton(rotaries.ccwchar, 0);
    };_

    if (result == DIR_CW) {
    Joystick.setButton(rotaries_.cwchar, 1); delay(50); Joystick.setButton(rotaries.cwchar, 0);
    };
    }
    }*

    I used this code but it does not work on uno I can’t find how to make it work on Uno and the code to program the switch_

I’ve watched several videos none use the uno card, however similar to a nano I admit being a beginner in arduino is to have launched into something huge

If You read the advicing topics telling how to use Forum and how to attach code, pictures etc. You will use “code tags”, the symbol up to the left in this window.
I tried to compile Your code but it fails, no keyboard.h.

What is working and what is failing with this code running on an UNO?

Hey, hey… Where will those pins be found on an UNO? How did You connect that?

byte rowPins[NUMROWS] = {21, 20, 19, 18, 15};
byte colPins[NUMCOLS] = {14, 16, 10, 9, 8};

this is a nano code for my code i modified it to work on uno

I can't find the joystick.h library and I seem to have seen that it only works on nano

can you tell me in this code that it is the code for the switches and for the rotary encoder ?

petitinixh: this is a nano code for my code i modified it to work on uno

I can't find the joystick.h library and I seem to have seen that it only works on nano

A nano and a uno use the same processor, an atmega328 so I doubt that is true.

No, I can't. A normal way to develope things like this is to estimate the number of I/O pins and buy a proper controller. Then You start learning how to read buttons, how to read joystcks, sensors etc.

Starting with a huge amount of unknown things in a bag is completely wrong. As I think this can't be done on an UNO. Too few I/O pins.

This code possibly works on a NANO. Why not buy a NANO?

« I believe that the UNO card is not made for the buttonbox, it is the Leonardo which is taken for that for a button box with a UNO card, it's more complicated » it comes from a site and a lot of button boxes used nano or micro

to avoid spending to buy a nano nevertheless I do not understand the code too much and I do not see the places where the switch and rotary encoder can work in this code

Don't buy huge projects from sites unless You are an experienced "programmer- and converter-" guy. Night time here.

it was to avoid spending more money by buying a real button box

Thanks for your help I will try again when I have the arduino nano.

//USE w ProMicro

This indicates the code is intended for a Pro Micro (or Arduino Micro). Nano is not the same as Micro/Pro Micro.

Being anoid by button reding issues I just made a simple matrix keyboard sketch. It works for switches, not for shortly pressed buttons because of the absence of debouncing. My sketch use 4 by 4 but can easily be modified to other sizes. Any interest? I used a simple UNO and 4 + 4 I/O. The result is a row*col matrix showing the state of the buttons.

Hi, Welcome to the forum.

Please read the post at the start of any forum , entitled "How to use this Forum". OR http://forum.arduino.cc/index.php/topic,148850.0.html. Then look down to item #7 about how to post your code. It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Can you please tell us your electronics, programming, arduino, hardware experience?

Thanks.. Tom... :)