Hello, I have two sketches that both compile without errors. I have attached both. Sketch A makes the Arduino appear as a game controller on win 10, but unfortunately it uses potentiometers connected to A0 thru A4. I want to use optical encoders connected to the digital side. My sketch B does that but it does not show up as a game controller. How do I combine sketch A and B? I want to keep the overall construct of sketch A, and simply strip out the potentiometer code, and insert the encoder code from sketch B. Please help
I did not write any of the sketches. I downloaded them, and I am just trying to combine both of them into one sketch. Unfortunately sketch A does everything I want, but it cant seem to recognize the optical encoders. Sketch B recognizes the encoders, but does not show up as a game controller in win 10. So I am trying to combine them with cu and paste. I am a newbie
// Program used to test the USB Joystick library when used as
// a Flight Controller on the Arduino Leonardo or Arduino
// Micro.
//
// Matthew Heironimus
// 2016-05-29 - Original Version
//------------------------------------------------------------
// Set to true to test "Auto Send" mode or false to test "Manual Send" mode.
//const bool testAutoSendMode = true;
const bool testAutoSendMode = false;
const unsigned long gcCycleDelta = 1000;
const unsigned long gcAnalogDelta = 25;
const unsigned long gcButtonDelta = 500;
unsigned long gNextTime = 0;
unsigned int gCurrentStep = 0;
void testSingleButtonPush(unsigned int button)
{
if (button > 0)
{
Joystick.releaseButton(button - 1);
}
if (button < 32)
{
Joystick.pressButton(button);
}
}
void testMultiButtonPush(unsigned int currentStep)
{
for (int button = 0; button < 32; button++)
{
if ((currentStep == 0) || (currentStep == 2))
{
if ((button % 2) == 0)
{
Joystick.pressButton(button);
} else if (currentStep != 2)
{
Joystick.releaseButton(button);
}
} // if ((currentStep == 0) || (currentStep == 2))
if ((currentStep == 1) || (currentStep == 2))
{
if ((button % 2) != 0)
{
Joystick.pressButton(button);
} else if (currentStep != 2)
{
Joystick.releaseButton(button);
}
} // if ((currentStep == 1) || (currentStep == 2))
if (currentStep == 3)
{
Joystick.releaseButton(button);
} // if (currentStep == 3)
} // for (int button = 0; button < 32; button++)
}
void testXYAxis(unsigned int currentStep)
{
int xAxis;
int yAxis;
// Read the current state of inputCLK
currentStateCLK = digitalRead(inputCLK);
// If the previous and the current state of the inputCLK are different then a pulse has occured
if (currentStateCLK != previousStateCLK){
// If the inputDT state is different than the inputCLK state then
// the encoder is rotating counterclockwise
if (digitalRead(inputDT) != currentStateCLK) {
counter --;
encdir ="CCW";
digitalWrite(ledCW, LOW);
digitalWrite(ledCCW, HIGH);
Here is the entire error list. Sorry about the confusion.
sketch_feb02a:157:9: error: expected constructor, destructor, or type conversion before '(' token
pinMode (inputCLK, INPUT);
^
sketch_feb02a:158:9: error: expected constructor, destructor, or type conversion before '(' token
pinMode (inputDT, INPUT);
^
sketch_feb02a:161:9: error: expected constructor, destructor, or type conversion before '(' token
pinMode (ledCW, OUTPUT);
^
sketch_feb02a:162:9: error: expected constructor, destructor, or type conversion before '(' token
pinMode (ledCCW, OUTPUT);
^
sketch_feb02a:165:1: error: 'Serial' does not name a type
Serial.begin (9600);
^~~~~~
sketch_feb02a:169:1: error: 'previousStateCLK' does not name a type
previousStateCLK = digitalRead(inputCLK);
^~~~~~~~~~~~~~~~
sketch_feb02a:171:1: error: expected declaration before '}' token
}
^
Multiple libraries were found for "Joystick.h"
Used: C:\Users\michael\Documents\Arduino\libraries\Joystick
Not used: C:\Users\michael\Documents\Arduino\libraries\ArduinoJoystickLibrary-master
Using library Joystick at version 2.0.5 in folder: C:\Users\michael\Documents\Arduino\libraries\Joystick
exit status 1
expected constructor, destructor, or type conversion before '(' token
This code is outside of any function. I assume it should be in setup().
// Set encoder pins as inputs
pinMode (inputCLK, INPUT);
pinMode (inputDT, INPUT);
// Set LED pins as outputs
pinMode (ledCW, OUTPUT);
pinMode (ledCCW, OUTPUT);
// Setup Serial Monitor
Serial.begin (9600);
// Read the initial state of inputCLK
// Assign to previousStateCLK variable
previousStateCLK = digitalRead(inputCLK);
}
You have 2 loop() functions.
Also, I believe the code was written for a different joystick library.
to give you a mechanical example:
if you would like to drive a 40 ton excavator.
You know how to drive a car. But you have no clue about the function of those pedals je joystick and these six levers to control this beast.
Will this work? no chance !
what do you have to learn?
Yes the basic function of all these levers, the joystick and the pedal. Otherwise you will damage a lot of things. The samw principle applys to writing code. if you don't start to learn you will be asking new basic question for moth