Your C.V.P joystick code is very cool!
I became interested in Arduino with your code.
I believe that there are endless possibilities in Arduino
So. It is thanks to you who always realize it.
But Your C.V.P joystick code is not easy to have to learn.
You said~
“ps. this firmware is inspired by Darran's project: Arduino UNO Big joystick HID firmware: http://hunt.net.nz/users/darran/weblog/15f92/
with out Darran's code I will never make this work. Thanks Darran.“
If you help me, I would like to receive your inspiration.
Above all, I thank for giving an answer from your busy day.
I also want to do this to start.
1. I had been download the files to this website.
http://hunt.net.nz/users/darran/weblog/15f92/
https://github.com/RICLAMER/Arduino_Big_Joystik
“Big Joystick Firmware”, “riclamer_big_joystik.ino”, “Arduino-big-joystick.c”, “Arduino-big-joystick.h”, “Descriptors.c”, “Descriptors.h”
2. I have Changed to “riclamer_big_joystik.ino”, as shown below
But I found some problems.
1) I dont know why starting from joystick button No 18, 19~~28.
: I want you to start from button No 6,7,8~~~
So I have Changed to riclamer_big_joystik.ino”, as shown below.
Please tell me about incorrect.
#undef DEBUG
#define NUM_BUTTONS 40 // you don't need to change this value
#define NUM_AXES 8 // 6 axes to UNO, and 8 to MEGA. If you are using UNO, don't need to change this value.
typedef struct joyReport_t {
int16_t axis[NUM_AXES];
uint8_t button[(NUM_BUTTONS+7)/8]; // 8 buttons per byte
} joyReport_t;
joyReport_t joyReport;
//uint8_t btn[12];
uint8_t btn[33]; //?
int fulloff = 0;
void setup(void);
void loop(void);
void setButton(joyReport_t *joy, uint8_t button);
void clearButton(joyReport_t *joy, uint8_t button);
void sendJoyReport(joyReport_t *report);
void setup()
{
//set pin to input Button MEGA2560R 2PIN~ 12PIN
// set pin to input Button MEGA2560R 14PIN~ 34PIN
for( int portId = 02; portId < 13; portId ++ ) //?
{
pinMode( portId, OUTPUT );
}
for( int portId = 14; portId < 34; portId ++ ) //?
{
pinMode( portId, INPUT_PULLUP );
}
Serial.begin(115200);
delay(200);
for (uint8_t ind=0; ind<8; ind++) {
joyReport.axis[ind] = ind*1000;
}
for (uint8_t ind=0; ind<sizeof(joyReport.button); ind++) {
joyReport.button[ind] = 0;
}
}
// Send an HID report to the USB interface
void sendJoyReport(struct joyReport_t *report)
{
#ifndef DEBUG
Serial.write((uint8_t *)report, sizeof(joyReport_t));
#else
// dump human readable output for debugging
for (uint8_t ind=0; ind<NUM_AXES; ind++) {
Serial.print("axis[");
Serial.print(ind);
Serial.print("]= ");
Serial.print(report->axis[ind]);
Serial.print(" ");
}
Serial.println();
for (uint8_t ind=0; ind<NUM_BUTTONS/8; ind++) {
Serial.print("button[");
Serial.print(ind);
Serial.print("]= ");
Serial.print(report->button[ind], HEX);
Serial.print(" ");
}
Serial.println();
#endif
}
// turn a button on
void setButton(joyReport_t *joy, uint8_t button)
{
uint8_t index = button/8;
uint8_t bit = button - 8*index;
joy->button[index] |= 1 << bit;
}
// turn a button off
void clearButton(joyReport_t *joy, uint8_t button)
{
uint8_t index = button/8;
uint8_t bit = button - 8*index;
joy->button[index] &= ~(1 << bit);
}
/*
* Read Digital port for Button
* Read Analog port for axis
*/
void loop()
{
// Create Matriz with value off switch button
for(int bt = 1; bt < 34; bt ++) //?
{
btn[bt]= digitalRead(bt+1);
}
// Power ON button if it is press. buton 17 at 28
for(int on=01; on < 34; on++) //?
{
if (btn[on] == LOW)
{
setButton(&joyReport, on+16);
//It start button no 16~. how to start buttons no 6, 7, 8~
// Serial.println("botao ON");
// Serial.println(on+16); How is this calculated?
}else{
fulloff = fulloff++;
} //Power off all Button, if all button are not press
if(fulloff == 34)
{
for(uint8_t cont=0; cont<40; cont++)
{
clearButton(&joyReport, cont);
}
// Serial.println("Every buttons is off");
}
}
/* Move all of the Analogic axis */
/* Arduino UNO have only 6 port. Will be necessary set to 0; the not used port */
/* In this example, i will use just 3 axis. X, Y, Z */
/* if you will use all 6 analog ports, set axis < 3, to axis < 5 */
for (uint8_t axis = 0; axis < 4; axis++) {
joyReport.axis[axis] = map(analogRead(axis), 0, 1023, -32768,32767 );
}
//Set to 0; the not used analog port.
//if you will use all 6 analog ports, exclude the lines, axis[3] at axis [5] */
//joyReport.axis[3] = 0;
joyReport.axis[4] = 0;
joyReport.axis[5] = 0;
joyReport.axis[6] = 0;
joyReport.axis[7] = 0;
joyReport.axis[8] = 0;
//Send Data to HID
sendJoyReport(&joyReport);
delay(100);
fulloff = 0;
}
Hpappy sunday. From John