I have successfully tested the Logitech 3d Pro joystick with the USB host shield, everything works as it should, I just don't understand how?
I
I want to modify the code so that the 'Button' event to allow for multiple buttons to be used simultaneously.
In the current format there is a single variable with a value of 0-12 (0= no button pressed).
I would like each button (there are 12 in total) on the joystick to return a boolean value with each cycle (loop or update).
I attempted to identify where and how the current code does this but became very quickly confused and I realise that I am totally out of my depth.
Also: what the the "correct" way to provide example code in the forum (instead of simply attaching)?
My Goal is to understand how this works, currently so that I can modify the various components myself and understand how the code structure works (best to know how to fix something BEFORE you break it).
When I started trying to understand the USBHID and USBHOST libraries I quickly learned that it is time to seek help from the community.
Logitech3DPro.ino (2.08 KB)
what the the "correct" way to provide example code in the forum
Like this
/*
* Simplified Logitech Extreme 3D Pro Joystick Report Parser, ready to go.
*/
#include <usbhid.h>
#include <hiduniversal.h>
#include <usbhub.h>
#include "le3dp_rptparser2.0.h"
#include <SPI.h>
#include <Servo.h>
USB Usb;
USBHub Hub(&Usb);
HIDUniversal Hid(&Usb);
JoystickEvents JoyEvents;
JoystickReportParser Joy(&JoyEvents);
Servo myservo; // create servo object to control a servo
//int potpin = 0; // analog pin used to connect the potentiometer
int val; // variable to read the value from the analog pin
void setup()
{
Serial.begin( 115200 );
#if !defined(__MIPSEL__)
while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
#endif
Serial.println("Start");
if (Usb.Init() == -1)
Serial.println("OSC did not start.");
delay( 200 );
if (!Hid.SetReportParser(0, &Joy))
ErrorMessage<uint8_t>(PSTR("SetReportParser"), 1 );
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop()
{
//
int Xval; // 0 - 1023
int Yval; // 0 - 1023
int Hat; // 0 - 15;
int Twist; // 0 - 255
int Slider; // 0 - 255
int Button; // 0 - 12 (0 = No button)
Usb.Task(); //Use to read joystick input to controller
JoyEvents.PrintValues(); //Returns joystick values to user
JoyEvents.GetValues(Xval, Yval, Hat, Twist, Slider, Button); //Copies joystick values to user
//val = Twist; // reads the value of the potentiometer (value between 0 and 1023)
val = map(Xval, 0, 1023, 0, 180); // scale it to use it with the servo (value between 0 and 180)
myservo.write(val); // sets the servo position according to the scaled value
delay(15); // waits for the servo to get there
}
Select the code in the IDE, right click, select Copy for Forum and post it here
Thank you @UKHeliBob, as you seem to have done this for me I will not go back and correct the original post to 'insert' the code.
Perhaps some other newbie will read this and take some learning(s) from-
A: my lack of knowledge, and
B: your clarification
I assume that you did not read Read this before posting a programming question before posting your question