Hi, i am having a problem with programming my arduino.I am trying to make a throttle for xplane12.
I did the mechanical stuff but my potentiometer is kind of glitchy.Basically what i am trying to say is that my potentiometer is giving me two different numbers.What i am trying to make is 250 and 251
252.I have already wrote one code for this but, it is not working.Here is the code that i wrote:
#include <Joystick.h>
#define Throttle A1
int throttle_ = 0;
Joystick_ Joystick(0x12, JOYSTICK_TYPE_JOYSTICK,0,0,false,false,false,false,false,false,false,true,true,true,false);
const bool initAutoSendState = true;
void setup() {
// put your setup code here, to run once:
Joystick.begin();
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
int throttle = 249;
throttle_ = analogRead(Throttle);
throttle_ = map(throttle_,0,1023,0,255);
if(throttle_ >= throttle){
int throttle_ = 252;
}
Joystick.setThrottle(throttle_);
Serial.println(throttle_);
}
Dont focus on Joystick.setThrottle(throttle_);
That's just to make ingame stuff work.
That is not important.
What is important is this part of the code:
if(throttle_ >= throttle){
int throttle_ = 252;
if you have a cheap pot or you are sending too much current through the pot, then make your test cover a small range of numbers. Greater than one and less than the other.
Then change the map scale. Easy peasy. I'm assuming the requirement is actually x >= 252. Such as
throttle_ = map(throttle_,0,1012,0,255);
Before you even touch the keys to program, you should run a test program to print un-converted ADC values. Then you absolutely know what the high pot setting will yield.