MicroController Gaming Controller Joystick Testing

Поделиться
HTML-код
  • Опубликовано: 8 фев 2025
  • Using an Adafruit Feather to create a controller that replaces the keyboard for computer gamers while still allowing precise mouse movements.

Комментарии • 4

  • @1040ugur
    @1040ugur 6 лет назад

    Code pls

  • @alexmarino328
    @alexmarino328  6 лет назад

    Final Code (including Joystick and Buttons)
    #include
    int button1 = 13;
    int button2 = 12;
    int button3 = 11;
    int button4 = 10;
    int button5 = 6;
    const int SW_pin = 2; // digital pin connected to switch output
    const int X_pin = 0; // analog pin connected to X output
    const int Y_pin = 1; // analog pin connected to Y output
    char shift = KEY_LEFT_SHIFT;
    void setup() {
    delay(5000);
    Keyboard.begin();
    pinMode(SW_pin, INPUT);
    digitalWrite(SW_pin, HIGH);
    Serial.begin(9600);
    pinMode(button1, INPUT_PULLUP);
    pinMode(button2, INPUT_PULLUP);
    pinMode(button3, INPUT_PULLUP);
    pinMode(button4, INPUT_PULLUP);
    pinMode(button5, INPUT_PULLUP);
    delay(5000);
    }
    void loop() {
    /* Serial.print("Switch: ");
    Serial.print(digitalRead(SW_pin));
    Serial.print("
    ");
    Serial.print("X-axis: ");
    Serial.print(analogRead(X_pin));
    Serial.print("
    ");
    Serial.print("Y-axis: ");
    Serial.println(analogRead(Y_pin));
    Serial.print("

    ");
    */
    if (analogRead(Y_pin) < 500) {
    Keyboard.press( 's' );
    Serial.print("s ");
    // delay(5);
    }
    if (analogRead(Y_pin) > 900) {
    Keyboard.press( 'w' );
    Serial.print("w ");
    // delay(100);
    }
    if (analogRead(Y_pin) > 500 && analogRead(Y_pin) < 900) {
    Keyboard.release( 'w' );
    Keyboard.release( 's' );
    // delay(100);
    }
    if (analogRead(X_pin) > 900) {
    Keyboard.press( 'd' );
    Serial.print("d ");
    // delay(100);
    }
    if (analogRead(X_pin) < 500) {
    Keyboard.press( 'a' );
    Serial.print("a ");
    // delay(100);
    }
    if (analogRead(X_pin) > 500 && analogRead(X_pin) < 900) {
    Keyboard.release( 'a' );
    Keyboard.release( 'd' );
    // delay(100);
    }
    if (digitalRead(SW_pin) == LOW) {
    Keyboard.press(shift);
    Serial.print("space");
    // delay(500);
    } else {
    Keyboard.release(shift);
    // delay(500);
    }
    if (digitalRead(button1) == HIGH) {
    Keyboard.press( 'x' );
    Serial.print("x ");
    // delay(500);
    } else {
    Keyboard.release( 'x' );
    // delay(500);
    }
    if (digitalRead(button2) == HIGH) {
    Keyboard.press( 'c' );
    Serial.print("c ");
    // delay(500);
    } else {
    Keyboard.release( 'c' );
    // delay(500);
    }
    if (digitalRead(button3) == HIGH) {
    Keyboard.press( 'q' );
    Serial.print("q ");
    // delay(500);
    } else {
    Keyboard.release( 'q' );
    // delay(500);
    }
    if (digitalRead(button4) == HIGH) {
    Keyboard.press( 'z' );
    Serial.print("z ");
    // delay(500);
    } else {
    Keyboard.release( 'z' );
    // delay(500);
    }
    if (digitalRead(button5) == HIGH) {
    Keyboard.press( 'e' );
    Serial.print("e ");
    // delay(500);
    } else {
    Keyboard.release( 'e' );
    // delay(500);
    }
    }