Hi,
Beginner in programming,
I have just started making a homemade joystick that will be used on a larger project (a motorcycle simulator).
So I equipped myself with an Arduino UNO R3 board with a set of potentiometers, load sensors, distance sensors, buttons.
With TINKERCAD I managed to create a code that works and returns me the correct information on the serial monitor.
Then with UNOJOY I configured the ARDUINO as a joystick.
When I test, the cross turns in all directions and the buttons flash...
Will any of you have an idea on the procedure to be carried out with the following code?
int axeX = A0; // signal de l'axe X sur entrée A0
int axeY = A1; // signal de l'axe Y sur entrée A1
int axeZ = A2; // signal de l'axe Z sur entrée A2
int Rapport_Sup = 0;
int Rapport_Inf = 0;
int Frein_Avant = 0;
int Frein_Arriere = 0;
long readUltrasonicDistance(int triggerPin, int echoPin)
{
pinMode(triggerPin, OUTPUT);
digitalWrite(triggerPin, LOW);
delayMicroseconds(2);
digitalWrite(triggerPin, HIGH);
delayMicroseconds(10);
digitalWrite(triggerPin, LOW);
pinMode(echoPin, INPUT);
return pulseIn(echoPin, HIGH);
}
void setup ()
{
pinMode (axeX, INPUT); // définition de A0 comme une entrée
pinMode (axeY, INPUT); // définition de A1 comme une entrée
pinMode (axeZ, INPUT); // définition de A2 comme une entrée
pinMode(7, INPUT); // définition de 7 comme une entrée
pinMode(6, INPUT); // définition de 6 comme une entrée
Serial.begin (9600);
}
void loop ()
{
float X, Y, Z;
X = analogRead (axeX) * (5.0 / 1023.0);
Y = analogRead (axeY) * (5.0 / 1023.0);
Z = analogRead (axeZ) * (5.0 / 1023.0);
Rapport_Sup = digitalRead(7);
Rapport_Inf = digitalRead(6);
Serial.print ("Direction_Droite: ");
Serial.print (X, 4);
Serial.println (" V");
Serial.print ("Direction_Gauche: ");
Serial.print (Y, 4);
Serial.println (" V");
Serial.print ("Accelerateur: ");
Serial.print (Z, 4);
Serial.println (" V");
Serial.println ("Rapport: ");
if (Rapport_Sup == 1)
Serial.println("Sup");
if (Rapport_Inf == 1)
Serial.println("Inf");
Serial.print ("Frein_Avant: ");
Frein_Avant = 0.01723 * readUltrasonicDistance(5, 4);
Serial.print(Frein_Avant);
Serial.println (" cm");
Serial.print ("Frein_Arriere: ");
Frein_Arriere = 0.01723 * readUltrasonicDistance(3, 2);
Serial.print(Frein_Arriere);
Serial.println (" cm");
Serial.print ("\n\n");
delay (1000);
}