Potentiometer as a keyboard

Halo semuanya, saya seorang gamer yang menyukai game simulator kereta, saya baru mengenal Arduino Leonardo dan saya memiliki masalah pemrograman dengan Arduino Leonardo, untuk membuat beberapa fungsi keyboard saya menggunakan potensiometer, yang saya maksud adalah ketika potensiometer diputar itu hanya menghasilkan 1 tombol yang berfungsi “Misalnya, pot berada di kisaran 0 dan 4000, tekan tombol” W "dan lepaskan tidak akan berulang, tetapi yang terjadi ketika potensiometer belum diputar terjadi input otomatis menekan “WWWWWWWWWWWWW …” tanpa batas. Bagaimana solusi untuk masalah ini.
Teeeeeeeest

#include “Keyboard.h”

#include “TSController.h”

#include “Joystick.h”

int TSController :: begin () {

Keyboard.begin ();

}

void TSController :: setThrottle (int n, mode int) {

kecepatan int = 0;

if ((n> 4000) || (n <0)) return;

jika (mode == 1) {

kecepatan = peta (n, 0, 4000, 0, 4000);

}

lain jika (mode = 2) {

kecepatan = peta (n, 0, 4000, 0, 2000);

}

lain jika (mode = 3) {

kecepatan = peta (n, 0, 4000, 0, 1000);

}

lain {

kembali;

}

if (digitalRead (A3) == LOW) {

if (kecepatan> ACCprev);

int del = (kecepatan - ACCprev);

// Kirim ASCII ‘w’,

Keyboard.write (104);

Keyboard.press (‘w’);

penundaan (del);

Keyboard.releaseAll ();

}

if (speed <ACCprev) {

int del = (ACCprev - kecepatan);

Keyboard.press (‘d’);

penundaan (del);

Keyboard.releaseAll ();

}

if ((speed <50) && (ACCprev> 50)) {

int del = 200;

Keyboard.press (‘d’);

penundaan (del);

Keyboard.releaseAll ();

}

ACCprev = kecepatan;

}

Wow!

IN engrish…

Hello everyone, I am a gamer who likes train simulator games, I am new to Arduino Leonardo and I have programming problems with Arduino Leonardo, to make some of my keyboard functions using a potentiometer, what I mean is when the potentiometer is rotated it only produces 1 working button " For example, the pot is in the range of 0 and 4000, press the “W” button and release will not be repeated, but what happens when the potentiometer has not been turned occurs automatic input pressing “WWWWWWWWWWWWW …” indefinitely. How to solve this problem.

The code snippet in code tags…

#include "Keyboard.h"
#include "TSController.h"
#include "Joystick.h"


int TSController :: begin () {

  Keyboard.begin ();
}


void TSController :: setThrottle (int n, mode int) {

  kecepatan int = 0;

  if ((n > 4000) || (n < 0)) return;
  jika (mode == 1) {
    kecepatan = peta (n, 0, 4000, 0, 4000);
  }
  lain jika (mode = 2) {
    kecepatan = peta (n, 0, 4000, 0, 2000);
  }
  lain jika (mode = 3) {
    kecepatan = peta (n, 0, 4000, 0, 1000);
  }
  lain {
    kembali;
  }
  if (digitalRead (A3) == LOW) {
    if (kecepatan > ACCprev);
    int del = (kecepatan - ACCprev);
    // Kirim ASCII 'w',
    Keyboard.write (104);
    Keyboard.press ('w');
    penundaan (del);
    Keyboard.releaseAll ();
  }
  if (speed < ACCprev) {
    int del = (ACCprev - kecepatan);
    Keyboard.press ('d');
    penundaan (del);
    Keyboard.releaseAll ();
  }
  if ((speed < 50) && (ACCprev > 50)) {
    int del = 200;
    Keyboard.press ('d');
    penundaan (del);
    Keyboard.releaseAll ();
  }
  ACCprev = kecepatan;
}

Have fun!

-jim lee

Hello everyone, I am a gamer who likes train simulator games, I am new to Arduino Leonardo and I have programming problems with Arduino Leonardo, to make some of my keyboard functions using a potentiometer, what I mean is when the potentiometer is rotated it only produces 1 working button " For example, the pot is in the range of 0 and 4000, press the “W” button and release will not be repeated, but what happens when the potentiometer has not been turned occurs automatic input pressing “WWWWWWWWWWWWW …” indefinitely. How to solve this problem.

#include “Keyboard.h”

#include “TSController.h”

#include “Joystick.h”

int TSController :: begin () {

Keyboard.begin ();

}

void TSController :: setThrottle (int n, int mode) {

velocity int = 0;

if ((n> 4000) || (n <0)) return;

if (mode == 1) {

speed = map (n, 0, 4000, 0, 4000);

}

else if (mode = 2) {

speed = map (n, 0, 4000, 0, 2000);

}

else if (mode = 3) {

speed = map (n, 0, 4000, 0, 1000);

}

other {

back;

}

if (digitalRead (A0) == LOW) {

if (speed> ACCprev);

int del = (speed - ACCprev);

// Send ASCII ‘w’,

Keyboard.write (104);

Keyboard.press (‘w’);

delay (del);

Keyboard.releaseAll ();

}

if (speed <ACCprev) {

int del = (ACCprev - speed);

Keyboard.press (‘d’);

delay (del);

Keyboard.releaseAll ();

}

if ((speed <50) && (ACCprev> 50)) {

int del = 200;

Keyboard.press (‘d’);

delay (del);

Keyboard.releaseAll ();

}

ACCprev = speed;

}

Topics merged

I don't know how you posted your code but it is in a real mess

Please follow the advice on posting a programming question given in Read this before posting a programming question

In particular note the advice to Auto format code in the IDE and to use code tags when posting code here as it prevents some combinations of characters in code being interpreted as HTML commands such as italics, bold or a smiley character, all of which render the code useless