Why does this code not work? (Teensy)

I am working on a set of foot pedals to help me in my photo editing. i have a set of foot pedals from a driving wheel which is broken so i have taken them apart and added an extra button as well as the 2 analog pedals.
this code is for my arduino compatiable teensy hid device

const int analogPin = A0;
const int analogPin1 = A1; // pin that the sensor is attached to
const int pinBtnUp = 20;
const int ledPin = 6; // pin that the LED is attached to
const int threshold = 900; // an arbitrary threshold level that's in the range of the analog input
const int threshold1 = 200;
boolean boolBtnUp;

void setup() {
pinMode(ledPin, OUTPUT);
pinMode( pinBtnUp, INPUT_PULLUP );
boolBtnUp = false;
}

void loop() {

int analogValue = analogRead(analogPin);
if (analogValue > threshold) {
digitalWrite(ledPin, HIGH);
Keyboard.set_key1( KEY_R );
}
else {
digitalWrite(ledPin,LOW);
Keyboard.set_key1( 0 );
}

int analogValue1 = analogRead(analogPin1);
if (analogValue1 < threshold1) {
digitalWrite(ledPin, HIGH);
Keyboard.set_key1( KEY_L );
}
else {
digitalWrite(ledPin,LOW);
Keyboard.set_key1( 0 );
}

boolean boolBtnUp = !digitalRead(pinBtnUp);
if ( boolBtnUp) {
digitalWrite(ledPin, HIGH);
Keyboard.set_key1( KEY_UP );
}
else {
digitalWrite(ledPin,LOW);
Keyboard.set_key1( 0 );
}

Keyboard.send_now();

}

the PB works but the 2 analog ones dont!. the led lights up whenever i press either of the pedals or the switch but the keypress is not triggered!(when i press the pedals the led lights dimmer than when i press the switch).

For some reason one of the pedals reads 1023 to 0 when you press it and the other reads 0-1023!
thanks in advance

For some reason one of the pedals reads 1023 to 0 when you press it and the other reads 0-1023!

reversed GND and +5V by accident?

yeh i realise that now any ideas about the code?

A very quick look at the code showed me the following:

if (analogValue > threshold) {

if (analogValue1 < threshold1) {

Try to expand it that every pedal has its own led?

Does the Keyboard.set_key1(..) of the button not overwrite the keys of the pedals?
You might need to add a few Keyboard.send_now(); 's

my 2 cnts,

thanks worked perfectily :wink: :slight_smile: