der joystick hat noch eine z achse.. also man kann den knübel noch verdrehen...
stimmt.. werde den mal durchmessen. danke für den tipp ![]()
meld mich wieder .
danke
der joystick hat noch eine z achse.. also man kann den knübel noch verdrehen...
stimmt.. werde den mal durchmessen. danke für den tipp ![]()
meld mich wieder .
danke
hab gerade mal gemessen.. 10,8 k ohm haben die potis.
jetzt muss ich nur noch sehen, wie ich das irgendwie alles in den sketch bekomme..
Die Außenanschlüsse auf GND und Vcc, den Mittelabgriff jeweils auf einen analogen Eingang.
Dann erst mal einlesen und die Werte auf dem seriellen Monitor ausgeben lassen.
Gruß Tommy
seht gut.. von 0- 1023..
kann ich diesen sketch aus dem video nutzen und versuchen umzubauen ?
weiß nur nicht wie ich die potis dazu schalte.. sonst muss ich mal weiter suchen.
danke schonmal bis hier hin
Welcher MC? Der klassische Nano hat 0...255 0 ... 1023. Du hast Recht, Fehler von mir.
@noiasca Danke für die Korrektur.
Gruß Tommy
Also zum testen hab ich noch so ein Uno aus nem Baukasten..
Für das Projekt bin ich mir noch nicht sicher was ich da verwenden soll..
Micro pro ? Plus Expander ? Ich kenn mich leider zu wenig aus.. am Ende würde ich halt gerne zwei Joysticks und vielleicht 20-25 Taster verwenden..
Aber ich tappe noch etwas im dunkeln und mache mehr oder weniger meine ersten Schritte was das Projekt angeht..
Natürlich hab ich schon etwas arduino Erfahrung..
Also die totalen Einsteiger Basic Sachen hab ich schonmal gemacht.
Ehrlich gesagt, hatte ich gedacht, ich finde ein passendes Sketch was halbwegs passt und änder bzw. Erweiter das ganze für potis und Taster..
Ob das alles so klappt.. bin ich noch unsicher..
Habe aber schonmal so ein kleinen Versuchsaufbau auf dem Steckbrett gebastelt..
Wie soll denn die Anbindung an den PC erfolgen? Als HID (Tastatur)?
Wenn ja, dann suche mal nach "Arduino HID". Beispiel
Für UNO/MEGA (original) musst Du den 16U2 umflashen (Hood-Loader), Klone mit CH340 gehen nicht. Am Besten ist ein Leonardo oder Micro Pro.
Ich selbst habe keine Erfahrung damit.
Zum Testen mit den Potis und Tastern/Schaltern kannst Du aber den UNO nehmen. Portexpander wirst Du zusätzlich für die Tasten/Schalter brauchen.
Gruß Tommy
Ja.. ich denke als HID Tastatur.. Ja.. ich hatte mir mal zwei Micro Pro bestellt.. aber weiß nicht welchen expander ich dazu am besten nehmen soll...
jap. danke für die Hilfe.
Gruß Marcell
Noch immer nicht? ![]()
Was brauchst Du?
Nur digitale Pins?
Dann such nach I2C Expander 16-Channel
Die Potis an die Analogen Eingänge und Für den Rest z.B. 16 Bit I2C IO-Erweiterungen MCP23017.
Gruß Tommy
ja.. sorry.. ![]()
ehm.. ich würde gerne zwei joystick betreiben..
die dann jeweils 3 potis betreiben..
wenn ich das richtig verstehe.. würde dann eigentlich ein micro pro mit seinen 4 analog pins ausreichen oder ? dazu dann diesen expander.
richtig ?
okay. dankeschön an alle.. würde mich dann nochmal melden wenn ich eine Frage dazu habe.. dankeeee
![]()
Für 2 Joysticks brauchst Du 6 analoge Eingänge. Der Micro Pro hat 129 davon (Pinout). Alles Andere an I2C (SCL/SDA).
Gruß Tommy
Edit: Pinout korrigiert
hallo.. mal ne kurze frage.. hab jetzt beide teile hier liegen.
so langsam wird es ernst.. ![]()
ist das richtig das der expander nur mit zwei kabeln verbunden wird ? vom micro pro a4 nach SDA und a5 nach SCL ?
kauft man sich am besten noch eine steckplatine ( steckbrett) wo man beide platinen drauf steckt um das ganze nachher zu verbauen oder wie macht man das am besten ?
jetzt muss ich mir mal das sketch ausm dem video zusammen basteln..
wollte erstmal nur einen schalter verbauen incl. joystick und keyboard library um mal zu testen ob der schalter im spiel auch funktoniert.. hab nämlich gelesen, dass man am besten nur taster verwenden sollte..(stand 2020)
danke schonmal
Und GND.
Und dann evtl. Versorgungsspannung.
Vcc und GND musst Du auch verbinden.
Steckbretter sind zum Testen da. Für die endgültige Lösung solltest Du Löten (Lochraster oder Leiterplatte entwickeln)
Gruß Tommy
danke euch.. also am besten dann eine lochraster platte und beide platinen mit den steckpins verbinden. hab jetzt auch ein video gefunden was gut für meine sache passne würde.
code müsste ich dann logischerweise abändern,
so... hab auf der arbeit jetzt ein wenig zeit gehabt zum löten..
hab die kabel von allen knöpfen verlängert. ein alle taster benutzen alle den gleichen ground. sollte der mit der matrix eigentlich kein problem darstellen oder ?
ich habe diesen example code den ich gerne nutzen möchte.
#include <Keypad.h>
#include <Joystick.h>
//DEFINITIONS
#define ENABLE_PULLUPS
#define NUMROTARIES ? //replace "?" with number of rotary encoders you are using
#define NUMBUTTONS ? //replace "?"with number of buttong you are using
#define NUMROWS ? //replace "?" with number of rows you have
#define NUMCOLS ? //replace "?" with number of columns you have
//BUTTON MATRIX
//first change number of rows and columns to match your button matrix,
//then replace all "?" with numbers (starting from 0)
byte buttons[NUMROWS][NUMCOLS] = {
{?,?,?,?},
{?,?,?,?},
{?,?,?,?},
{?,?,?,?}
};
struct rotariesdef {
byte pin1;
byte pin2;
int ccwchar;
int cwchar;
volatile unsigned char state;
};
//ROTARY ENCODERS
//each line controls a different rotary encoder
//the first two numbers refer to the pins the encoder is connected to
//the second two are the buttons each click of the encoder wil press
//do NOT exceed 31 for the final button number
rotariesdef rotaries[NUMROTARIES] {
{0,1,22,23,0}, //rotary 1
{2,3,24,25,0}, //rotary 2
{4,5,26,27,0}, //rotary 3
{6,7,28,29,0} //rotary 4
};
#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
//BUTTON MATRIX PART 2
byte rowPins[NUMROWS] = {?,?,?}; //change "?" to the pins the rows of your button matrix are connected to
byte colPins[NUMCOLS] = {?,?,?,?}; //change "?" to the pins the rows of your button matrix are connected to
Keypad buttbx = Keypad( makeKeymap(buttons), rowPins, colPins, NUMROWS, NUMCOLS);
//JOYSTICK SETTINGS
Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID,
JOYSTICK_TYPE_JOYSTICK,
32, //number of buttons
0, //number of hat switches
//Set as many axis to "true" as you have potentiometers for
false, // y axis
false, // x axis
false, // z axis
false, // rx axis
false, // ry axis
false, // rz axis
false, // rudder
false, // throttle
false, // accelerator
false, // brake
false); // steering wheel
const int numReadings = 20;
int readings[numReadings]; // the readings from the analog input
int index = 0; // the index of the current reading
int total = 0; // the running total
int currentOutputLevel = 0;
//POTENTIOMETERS PART 1
//add all the axis' which are enabled above
int zAxis_ = 0;
int RxAxis_ = 0;
//POTENTIOMETERS PART 2
//Which pins are your potentiometers connected to?
int potentiometerPin1 = ?; //Change "?" to the pin your potentiometer is connected to
int potentiometerPin2 = ?;
const bool initAutoSendState = true;
void setup() {
Joystick.begin();
rotary_init();
for (int thisReading = 0; thisReading < numReadings; thisReading++) {
readings[thisReading] = 0;
}
}
void loop() {
CheckAllEncoders();
CheckAllButtons();
CheckAllPotentiometers();
}
//POTENTIOMETERS PART 3
//change the details to match teh details above for each potentiometer you are using
void CheckAllPotentiometers(){
//potentiometer 1
currentOutputLevel = getAverageOutput(potentiometerPin1);
zAxis_ = map(currentOutputLevel,0,1023,0,255);
Joystick.setZAxis(zAxis_);
//potentiometer 2
currentOutputLevel = getAverageOutput(potentiometerPin2);
RxAxis_ = map(currentOutputLevel,0,1023,0,255);
Joystick.setRxAxis(RxAxis_);
}
int getAverageOutput(int pinToRead){
index = 0;
total = 0;
while (index < numReadings){
readings[index] = analogRead(pinToRead);
total = total + readings[index];
index = index + 1;
//delay (1);
}
return total / numReadings;
}
void CheckAllButtons(void) {
if (buttbx.getKeys())
{
for (int i=0; i<LIST_MAX; i++)
{
if ( buttbx.key[i].stateChanged )
{
switch (buttbx.key[i].kstate) {
case PRESSED:
case HOLD:
Joystick.setButton(buttbx.key[i].kchar, 1);
break;
case RELEASED:
case IDLE:
Joystick.setButton(buttbx.key[i].kchar, 0);
break;
}
}
}
}
}
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
}
}
unsigned char rotary_process(int _i) {
//Serial.print("Processing rotary: ");
//Serial.println(_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) {
Serial.println("Checking rotaries");
for (int i=0;i<NUMROTARIES;i++) {
unsigned char result = rotary_process(i);
if (result == DIR_CCW) {
Serial.print("Rotary ");
Serial.print(i);
Serial.println(" <<< Going CCW");
Joystick.setButton(rotaries[i].ccwchar, 1); delay(50); Joystick.setButton(rotaries[i].ccwchar, 0);
};
if (result == DIR_CW) {
Serial.print("Rotary ");
Serial.print(i);
Serial.println(" >>> Going CW");
Joystick.setButton(rotaries[i].cwchar, 1); delay(50); Joystick.setButton(rotaries[i].cwchar, 0);
};
}
Serial.println("Done checking");
}
hierzu hab ich noch eine Frage in dieser zeile.
//JOYSTICK SETTINGS
Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID,
JOYSTICK_TYPE_JOYSTICK,
32, //number of buttons
0, //number of hat switches
//Set as many axis to "true" as you have potentiometers for
false, // y axis
false, // x axis
false, // z axis
false, // rx axis
false, // ry axis
false, // rz axis
false, // rudder
false, // throttle
false, // accelerator
false, // brake
false); // steering wheel
const int numReadings = 20;
int readings[numReadings]; // the readings from the analog input
int index = 0; // the index of the current reading
int total = 0; // the running total
int currentOutputLevel = 0;
//POTENTIOMETERS PART 1
//add all the axis' which are enabled above
int zAxis_ = 0;
int RxAxis_ = 0;
//POTENTIOMETERS PART 2
//Which pins are your potentiometers connected to?
int potentiometerPin1 = ?; //Change "?" to the pin your potentiometer is connected to
int potentiometerPin2 = ?;
const bool initAutoSendState = true;
was mache ich wenn ich zwei joysticks einbinden möchte ?
danke für die auskunft.
morgen kommen die anderen taster und joystick.. hoffentlich passen alle taster auf die matrix.... ![]()
wieviel buttons sind maximum? 32 ?
Achja..noch eine Frage.. sorry.
Ich hab gerade mal meinen Micro pro hier mit deinem.pinout von deinem Link verglichen..
Meiner ist etwas kleiner.. könnte das ein Problem geben ?
Hilfe..bitte ![]()
Bei einer Matrix gibt es keinen GND. Schau dir mal https://www.gebe.net/download/ghostkey_d.pdf an.
Fang doch mal mit einem Taster an.