Hi team!
update 2:
==> red light on giga when i want to use more than 3 times the code "USBJoystick.h"
1 for normal joystick
2 for 2 rotary encoders
I would like one more for an other encoder but not possible... An idea?
I keep creating a HID joystick with the arduino GIGA R1 for use in Windows 10.
i used <USBJoystick.h> that works in HID to controle x y moves (and 1 button),it works.
I used the same code to add several buttons (simple buttons and Touch Sensor Modul TTP223B), it works).
I tweak the same code again with rotary encoder. Is there an other way ? Weerd ? No?
I found nothing else code HID for GIGA for buttons or encoder...
So i did this crazy tweak:
Code (not all the code):
#include <USBJoystick.h>
USBJoystick joystick2;// use encoder
int joystick2xValue = 0;// x
int joystick2yValue = 0;// y
// encoder
int switchState = HIGH;
int pinA = 50; // Rotary encoder Pin A
int pinB = 52; // Rotary encoder Pin B
int pinAstateCurrent = LOW; // Current state of Pin A
int pinAStateLast = pinAstateCurrent; // Last read value of Pin A
// Setup a RotaryEncoder with 4 steps per latch for the 2 signal input pins:
// RotaryEncoder encoder(PIN_IN1, PIN_IN2, RotaryEncoder::LatchMode::FOUR3
// Setup a RotaryEncoder with 2 steps per latch for the 2 signal input pins: set TWO03
RotaryEncoder encoder(pinA , pinB , RotaryEncoder::LatchMode::FOUR3);
void setup () {
pinMode (pinA, INPUT);
pinMode (pinB, INPUT);
// interrupt for best control = "void update" at the end.
attachInterrupt(digitalPinToInterrupt(pinB), update, CHANGE);
}; // end setup
void loop () {
// encoder result
if ((pinAStateLast == LOW) && (pinAstateCurrent == HIGH))
{
if (digitalRead(pinB) == HIGH)
{joystick2xValue =1000;joystick2.update(0,0,joystick2xValue,0,0,4);}
else
{joystick2yValue =1000;joystick2.update(0,0,0,joystick2yValue,0,4);}
}
pinAStateLast = pinAstateCurrent; // Store the latest read
}// end loop
// interrupt code
void update() {
pinAstateCurrent = digitalRead(pinA);
}
In windows 10 i use the software AntimicroX for assing keys (a, r, left arrow...) .
it works but it seems to be birarre !
i try to use togather:
#include <PluggableUSBHID.h>
#include <USBKeyboard.h>
#include <USBJoystick.h>
the giga put a red light ! Even without any other code...
Well what do you think ?
Thanks a lot !