Hi there,
I'm fairly new to this library, browsing through your examples.
I'm using an Adafruit Thumbstick (
https://www.adafruit.com/product/512) which supports two axes. I've wired that part to A8 and A9 on an Arduino Due.
My nonworking sketch so far: (btw, there some more parts assigned to that due).
I assume that I have to add another encoder somwhow, instead of another ArduinoAnalogDevice abstraction... hmmm
Cheers,
Peter
/******************************************************************************************
*** TRN V1.0 - Arduino Due ***
******************************************************************************************
* Kommunikation mit Mega via Serial3, 115K *
* Kommunikation mit PC via Serial, 115K *
* ****************************************************************************************
* Shields: *
* GShield V5b *
* *
* Hardware: *
* 1X Analog Joystick, 2x Analog, 1x Digital Switch [A08, A09][DI29] *
* 3X Taster, [DI30, DI31, Di32] *
* 1X Keyboard 3x4, [DI22-DI28] *
* 4X Endschalter, 2 davon benutzt, [DI34-DI37] *
* 1X Z-Achse, StepPin 4, DirPin 7, in Verwendung *
* 1X Y-Achse, StepPin 3, DirPin 6, nicht in Verwendung *
* 1X X-Achse, StepPin 2, DirPin 5, nicht in Verwendung *
* Stepper DisablePin = 8 *
*****************************************************************************************/
#include <IoAbstraction.h>
#include <KeyboardManager.h>
#include <JoystickSwitchInput.h>
#include <AccelStepper.h>
#include <MultiStepper.h>
///////////////////////////////////////////////////////////
// Definitionen Joystick //
///////////////////////////////////////////////////////////
#define JOYSTICK_X A8
#define JOYSTICK_Y A9
ArduinoAnalogDevice analogDevice1;
ArduinoAnalogDevice analogDevice2;
IoAbstractionRef arduinoPins = ioUsingArduino();
// JoyX Event
void onEncoderJoyXChange(int newXValue) {
Serial.print("New joystick X value: ");
Serial.print(newXValue);
Serial.print(", analog in ");
Serial.println(analogDevice1.getCurrentValue(JOYSTICK_X));
}
// JoyY Event
void onEncoderJoyYChange(int newYValue) {
Serial.print("New joystick Y value: ");
Serial.print(newYValue);
Serial.print(", analog in ");
Serial.println(analogDevice2.getCurrentValue(JOYSTICK_Y));
}
///////////////////////////////////////////////////////////
// Definitionen Keyboard //
///////////////////////////////////////////////////////////
MAKE_KEYBOARD_LAYOUT_3X4(keyLayout)
MatrixKeyboardManager keyboard;
IoAbstractionRef arduinoIo = ioUsingArduino();
class MyKeyboardListener : public KeyboardListener {
public:
void keyPressed(char key, bool held) override {
Serial.print("Key ");
Serial.print(key);
Serial.print(" is pressed, held = ");
Serial.println(held);
}
void keyReleased(char key) override {
Serial.print("Released ");
Serial.println(key);
}
} keyListener;
///////////////////////////////////////////////////////////
// Setup - RunOnce //
///////////////////////////////////////////////////////////
void setup() {
while(!Serial);
Serial.begin(115200);
// Keyboard
keyLayout.setRowPin(0, 25);
keyLayout.setRowPin(1, 26);
keyLayout.setRowPin(2, 27);
keyLayout.setRowPin(3, 28);
keyLayout.setColPin(0, 22);
keyLayout.setColPin(1, 23);
keyLayout.setColPin(2, 24);
keyboard.initialise(arduinoIo, &keyLayout, &keyListener);
keyboard.setRepeatKeyMillis(850, 350);
// Joystick X/Y
switches.initialise(arduinoPins, true);
setupAnalogJoystickEncoder(&analogDevice1 ,JOYSTICK_X, onEncoderJoyXChange);
setupAnalogJoystickEncoder(&analogDevice2, JOYSTICK_Y, onEncoderJoyYChange);
switches.changeEncoderPrecision(500, 250);
Serial.println("Setup done.");
}
void loop() {
taskManager.runLoop();
}