Having problems with getting the brake to work.

Hi all, I'm having problems with getting a brake input. The throttle works no problem but the brake doesn't. If I use Joystick.setBrake(analogRead(A2)); is does work but isn't smooth enough. The brake and throttle use the same hardware and are wired the same (only difference on is on A1 and one is on A2). I've verified that it isn't a hardware problem.

#include "Joystick.h"

Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID,
  JOYSTICK_TYPE_JOYSTICK, 0, 0, false, false, true, false, false, false, false, true, false, true, false);

  //int RzAxis;
  int brake;
  int throttle;
  
  void setup()
{
  Joystick.begin();
  Serial.begin(9600);
}
  void loop()
  {     
        //Joystick.setBrake(analogRead(A2));
   
        brake = analogRead(A2);
        brake = map(brake,0,50,0,127.5);
        Joystick.setBrake(brake);
  
        throttle = analogRead(A1);
        throttle = map(throttle,0,50,0,127.5);
        Joystick.setThrottle(throttle);

        Joystick.sendState();
        delay(5);
  }

Update: I'm trying to replace the stock fanatec clubsport V2 (sim racing pedals) electronics with two hall-effect sensors, a loadcell (w amp) and a arduino leonardo. For now I've only conntected the 2 halll sensors (simply to 5v, ground and A1 or A2). In the serial monitor both seem to work fine but in windows one behaves different compared to the other (see video Imgur: The magic of the Internet). In the video I used this code.

#include "Joystick.h"

Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID,
  JOYSTICK_TYPE_JOYSTICK, 0, 0, false, false, true, false, false, false, false, true, false, true, false);

  //int RzAxis;
  int brake;
  int throttle;

  
  void setup()
{
  Joystick.begin();
  Serial.begin(9600);
}
  void loop()
  {     
        Joystick.setBrake(analogRead(A2));
        Joystick.setThrottle(analogRead(A1));

  int y1 = analogRead(A1);
  int y4 = analogRead(A2);
       Serial.print(y1);
       Serial.print(" ");
       Serial.println(y4); 
       
       delay(10);
  }     

Update 2: I fixed it by celebrating it in windows.

Come on give us a bit of a clue. What are you making?
Robot?
Toy car?
Buggy?
Real Car?
Gaming controller?

Can you post your schematic as well please.

You might want to read the how to get the best from this forum sticky post at the head of each forum section.

Hi,
Try these line added to your code;

        brake = analogRead(A2);
        brake = analogRead(A2);
        brake = map(brake,0,50,0,127.5);
        Joystick.setBrake(brake);
  
        throttle = analogRead(A1);
        throttle = analogRead(A1);
        throttle = map(throttle,0,50,0,127.5);
        Joystick.setThrottle(throttle)

There is only one ADC in the controller, it is multiplexed to each input.
It requires time after selecting an input to for the ADC to get a stable reading.
Reading each input twice helps to give the ADC time.

Tom... :smiley: :+1: :coffee: :australia:

Hi,
Try these line added to your code;

    brake = analogRead(A2);
    brake = analogRead(A2);
    brake = map(brake,0,50,0,127.5);
    Joystick.setBrake(brake);

    throttle = analogRead(A1);
    throttle = analogRead(A1);
    throttle = map(throttle,0,50,0,127.5);
    Joystick.setThrottle(throttle)

I tried it but it sadly made no difference

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.