Skip to main content

Arduino Nano Keyboard. keysKeys keeps pressed

I'm new in coding with Arduino, and tryI am trying to make a one hand keyboard with joystick as personal project,. I trytried to make it print some ASCII characters, but I don't know why the button keeps pushed and don't show the ASCII I declare.


#include <Keyboard.h>
#include <Mouse.h>
//IndexFinger=IF,MiddleFinger=MF,RingFinger=RF
//LittleFinger=LF
int fingerCodes[3][4]={
  {LF_Up, RF_Up, MF_Up, IF_Up},
  {LF_Mid, RF_Mid, MF_Mid, IF_Mid},
  {LF_Down, RF_Down, MF_Down, IF_Down}
}
int asciiCodes[3][4]={
  {33, 34, 35, 36},
  {37, 38, 39, 40},
  {41, 42, 43, 44}
}
//a
int x=0;
int y=0;
const int joystickVRx1 = A0;
const int joystickVRy1 = A1;
const int joystickButton1 = 14;

// Define the FPS
const int FPS = 120;

// Initialize the last time variable
unsigned long lastTime = 5;

// Define the functions
void finger_ButtonsControl(int x, int y);
void joystickMovementControl(int joystickvrx, int joystickvry, int joystickButton1);
void setup() {
  // Initialize the serial port
  Serial.begin(115200);
  // Set the button pins as input
  pinMode(joystickVRx1,INPUT);
  pinMode(joystickVRy1,INPUT);
  for (int i = 2;i<11;i++){
    pinMode(i,OUTPUT);
  }
  Keyboard.begin();
  Mouse.begin();
}

void loop() {
  // Check if it's time to update the controls
  if ((millis() - lastTime) > 5) {
    // Update finger buttons
    finger_ButtonsControl(x,y);
    // Update the joystick movement
    joystickMovementControl(joystickVRx1, joystickVRy1, joystickButton1);
    // Reset the last time variable
    lastTime = millis();
  }
  Keyboard.releaseAll();
}

// Function to control finger buttons
void finger_ButtonsControl(int x, int y) {
  // Check if a button is pressed
  for (int x=2;x<5;x++){
    for (int y=5;y<9;y++){
      buttonState_x = digitalRead(x);
      buttonState_y = digitalRead(y);
      if (buttonState_x == HIGH && buttonState_y == HIGH){
        x=x-2;
        y=y-5;
        Keyboard.write(asciiCodes[x][y]);
      }
}

// Function to control the joystick movement
void joystickMovementControl(int joystickvrx, int joystickvry, int joystickButton1) {
  // Read the joystick values
  int x = analogRead(joystickvrx);
  int y = analogRead(joystickvry);
  if (digitalRead(joystickButton1) == LOW) {
    Keyboard.write(245);
  }
}


#include <Keyboard.h>
#include <Mouse.h>
//IndexFinger=IF,MiddleFinger=MF,RingFinger=RF
//LittleFinger=LF
int fingerCodes[3][4]={
  {LF_Up, RF_Up, MF_Up, IF_Up},
  {LF_Mid, RF_Mid, MF_Mid, IF_Mid},
  {LF_Down, RF_Down, MF_Down, IF_Down}
}
int asciiCodes[3][4]={
  {33, 34, 35, 36},
  {37, 38, 39, 40},
  {41, 42, 43, 44}
}
//a
int x=0;
int y=0;
const int joystickVRx1 = A0;
const int joystickVRy1 = A1;
const int joystickButton1 = 14;

// Define the FPS
const int FPS = 120;

// Initialize the last time variable
unsigned long lastTime = 5;

// Define the functions
void finger_ButtonsControl(int x, int y);
void joystickMovementControl(int joystickvrx, int joystickvry, int joystickButton1);
void setup() {
  // Initialize the serial port
  Serial.begin(115200);
  // Set the button pins as input
  pinMode(joystickVRx1,INPUT);
  pinMode(joystickVRy1,INPUT);
  for (int i = 2;i<11;i++){
    pinMode(i,OUTPUT);
  }
  Keyboard.begin();
  Mouse.begin();
}

void loop() {
  // Check if it's time to update the controls
  if ((millis() - lastTime) > 5) {
    // Update finger buttons
    finger_ButtonsControl(x,y);
    // Update the joystick movement
    joystickMovementControl(joystickVRx1, joystickVRy1, joystickButton1);
    // Reset the last time variable
    lastTime = millis();
  }
  Keyboard.releaseAll();
}

// Function to control finger buttons
void finger_ButtonsControl(int x, int y) {
  // Check if a button is pressed
  for (int x=2;x<5;x++){
    for (int y=5;y<9;y++){
      buttonState_x = digitalRead(x);
      buttonState_y = digitalRead(y);
      if (buttonState_x == HIGH && buttonState_y == HIGH){
        x=x-2;
        y=y-5;
        Keyboard.write(asciiCodes[x][y]);
      }
}

// Function to control the joystick movement
void joystickMovementControl(int joystickvrx, int joystickvry, int joystickButton1) {
  // Read the joystick values
  int x = analogRead(joystickvrx);
  int y = analogRead(joystickvry);
  if (digitalRead(joystickButton1) == LOW) {
    Keyboard.write(245);
  }
}


Arduino Nano Keyboard. keys keeps pressed

I'm new in coding with Arduino, and try to make a one hand keyboard with joystick as personal project, I try to make it print some ASCII characters, but don't know why the button keeps pushed and don't show the ASCII I declare


#include <Keyboard.h>
#include <Mouse.h>
//IndexFinger=IF,MiddleFinger=MF,RingFinger=RF
//LittleFinger=LF
int fingerCodes[3][4]={
  {LF_Up, RF_Up, MF_Up, IF_Up},
  {LF_Mid, RF_Mid, MF_Mid, IF_Mid},
  {LF_Down, RF_Down, MF_Down, IF_Down}
}
int asciiCodes[3][4]={
  {33, 34, 35, 36},
  {37, 38, 39, 40},
  {41, 42, 43, 44}
}
//a
int x=0;
int y=0;
const int joystickVRx1 = A0;
const int joystickVRy1 = A1;
const int joystickButton1 = 14;

// Define the FPS
const int FPS = 120;

// Initialize the last time variable
unsigned long lastTime = 5;

// Define the functions
void finger_ButtonsControl(int x, int y);
void joystickMovementControl(int joystickvrx, int joystickvry, int joystickButton1);
void setup() {
  // Initialize the serial port
  Serial.begin(115200);
  // Set the button pins as input
  pinMode(joystickVRx1,INPUT);
  pinMode(joystickVRy1,INPUT);
  for (int i = 2;i<11;i++){
    pinMode(i,OUTPUT);
  }
  Keyboard.begin();
  Mouse.begin();
}

void loop() {
  // Check if it's time to update the controls
  if ((millis() - lastTime) > 5) {
    // Update finger buttons
    finger_ButtonsControl(x,y);
    // Update the joystick movement
    joystickMovementControl(joystickVRx1, joystickVRy1, joystickButton1);
    // Reset the last time variable
    lastTime = millis();
  }
  Keyboard.releaseAll();
}

// Function to control finger buttons
void finger_ButtonsControl(int x, int y) {
  // Check if a button is pressed
  for (int x=2;x<5;x++){
    for (int y=5;y<9;y++){
      buttonState_x = digitalRead(x);
      buttonState_y = digitalRead(y);
      if (buttonState_x == HIGH && buttonState_y == HIGH){
        x=x-2;
        y=y-5;
        Keyboard.write(asciiCodes[x][y]);
      }
}

// Function to control the joystick movement
void joystickMovementControl(int joystickvrx, int joystickvry, int joystickButton1) {
  // Read the joystick values
  int x = analogRead(joystickvrx);
  int y = analogRead(joystickvry);
  if (digitalRead(joystickButton1) == LOW) {
    Keyboard.write(245);
  }
}


Arduino Nano Keyboard. Keys keeps pressed

I'm new in coding with Arduino, and I am trying to make a one hand keyboard with joystick as personal project. I tried to make it print some ASCII characters, but I don't know why the button keeps pushed and don't show the ASCII I declare.

#include <Keyboard.h>
#include <Mouse.h>
//IndexFinger=IF,MiddleFinger=MF,RingFinger=RF
//LittleFinger=LF
int fingerCodes[3][4]={
  {LF_Up, RF_Up, MF_Up, IF_Up},
  {LF_Mid, RF_Mid, MF_Mid, IF_Mid},
  {LF_Down, RF_Down, MF_Down, IF_Down}
}
int asciiCodes[3][4]={
  {33, 34, 35, 36},
  {37, 38, 39, 40},
  {41, 42, 43, 44}
}
//a
int x=0;
int y=0;
const int joystickVRx1 = A0;
const int joystickVRy1 = A1;
const int joystickButton1 = 14;

// Define the FPS
const int FPS = 120;

// Initialize the last time variable
unsigned long lastTime = 5;

// Define the functions
void finger_ButtonsControl(int x, int y);
void joystickMovementControl(int joystickvrx, int joystickvry, int joystickButton1);
void setup() {
  // Initialize the serial port
  Serial.begin(115200);
  // Set the button pins as input
  pinMode(joystickVRx1,INPUT);
  pinMode(joystickVRy1,INPUT);
  for (int i = 2;i<11;i++){
    pinMode(i,OUTPUT);
  }
  Keyboard.begin();
  Mouse.begin();
}

void loop() {
  // Check if it's time to update the controls
  if ((millis() - lastTime) > 5) {
    // Update finger buttons
    finger_ButtonsControl(x,y);
    // Update the joystick movement
    joystickMovementControl(joystickVRx1, joystickVRy1, joystickButton1);
    // Reset the last time variable
    lastTime = millis();
  }
  Keyboard.releaseAll();
}

// Function to control finger buttons
void finger_ButtonsControl(int x, int y) {
  // Check if a button is pressed
  for (int x=2;x<5;x++){
    for (int y=5;y<9;y++){
      buttonState_x = digitalRead(x);
      buttonState_y = digitalRead(y);
      if (buttonState_x == HIGH && buttonState_y == HIGH){
        x=x-2;
        y=y-5;
        Keyboard.write(asciiCodes[x][y]);
      }
}

// Function to control the joystick movement
void joystickMovementControl(int joystickvrx, int joystickvry, int joystickButton1) {
  // Read the joystick values
  int x = analogRead(joystickvrx);
  int y = analogRead(joystickvry);
  if (digitalRead(joystickButton1) == LOW) {
    Keyboard.write(245);
  }
}


Source Link

Arduino Nano Keyboard. keys keeps pressed

I'm new in coding with Arduino, and try to make a one hand keyboard with joystick as personal project, I try to make it print some ASCII characters, but don't know why the button keeps pushed and don't show the ASCII I declare


#include <Keyboard.h>
#include <Mouse.h>
//IndexFinger=IF,MiddleFinger=MF,RingFinger=RF
//LittleFinger=LF
int fingerCodes[3][4]={
  {LF_Up, RF_Up, MF_Up, IF_Up},
  {LF_Mid, RF_Mid, MF_Mid, IF_Mid},
  {LF_Down, RF_Down, MF_Down, IF_Down}
}
int asciiCodes[3][4]={
  {33, 34, 35, 36},
  {37, 38, 39, 40},
  {41, 42, 43, 44}
}
//a
int x=0;
int y=0;
const int joystickVRx1 = A0;
const int joystickVRy1 = A1;
const int joystickButton1 = 14;

// Define the FPS
const int FPS = 120;

// Initialize the last time variable
unsigned long lastTime = 5;

// Define the functions
void finger_ButtonsControl(int x, int y);
void joystickMovementControl(int joystickvrx, int joystickvry, int joystickButton1);
void setup() {
  // Initialize the serial port
  Serial.begin(115200);
  // Set the button pins as input
  pinMode(joystickVRx1,INPUT);
  pinMode(joystickVRy1,INPUT);
  for (int i = 2;i<11;i++){
    pinMode(i,OUTPUT);
  }
  Keyboard.begin();
  Mouse.begin();
}

void loop() {
  // Check if it's time to update the controls
  if ((millis() - lastTime) > 5) {
    // Update finger buttons
    finger_ButtonsControl(x,y);
    // Update the joystick movement
    joystickMovementControl(joystickVRx1, joystickVRy1, joystickButton1);
    // Reset the last time variable
    lastTime = millis();
  }
  Keyboard.releaseAll();
}

// Function to control finger buttons
void finger_ButtonsControl(int x, int y) {
  // Check if a button is pressed
  for (int x=2;x<5;x++){
    for (int y=5;y<9;y++){
      buttonState_x = digitalRead(x);
      buttonState_y = digitalRead(y);
      if (buttonState_x == HIGH && buttonState_y == HIGH){
        x=x-2;
        y=y-5;
        Keyboard.write(asciiCodes[x][y]);
      }
}

// Function to control the joystick movement
void joystickMovementControl(int joystickvrx, int joystickvry, int joystickButton1) {
  // Read the joystick values
  int x = analogRead(joystickvrx);
  int y = analogRead(joystickvry);
  if (digitalRead(joystickButton1) == LOW) {
    Keyboard.write(245);
  }
}