help with code, making a keyboard input 3d printed

What i dont understand is none of the keys are outputing what i asked except the analog ones.

ESC, SHIFT, CRTL do not work i get =ET instead

one of the buttons shows up as “q” but there isnt even a q in my code.

anyone care to help me?

using this board KeeYees Pro Micro ATmega32U4 5V 16MHz Micro USB Development Board Module Microcontroller for Arduino IDE Leonardo Bootloader

#include <Keyboard.h>

//#define ENCODER_OPTIMIZE_INTERRUPTS
//#include <Encoder.h>
//Encoder myEnc(4,5);  //quad encoder on PD0, PD1

void setup() {
  // put your setup code here, to run once:

  pinMode(1, INPUT_PULLUP);
  pinMode(0, INPUT_PULLUP);
  pinMode(2, INPUT_PULLUP);
  pinMode(3, INPUT_PULLUP);
  pinMode(4, INPUT_PULLUP);
  pinMode(5, INPUT_PULLUP);
  pinMode(6, INPUT_PULLUP);
  pinMode(7, INPUT_PULLUP);
  pinMode(8, INPUT_PULLUP);
  pinMode(9, INPUT_PULLUP);
  pinMode(21, INPUT_PULLUP);
  pinMode(20, INPUT_PULLUP);
  pinMode(19, INPUT_PULLUP);
  pinMode(18, INPUT_PULLUP);
  pinMode(15, INPUT_PULLUP);
  pinMode(14, INPUT_PULLUP);
  pinMode(16, INPUT_PULLUP);
  pinMode(10, INPUT_PULLUP);
  Keyboard.begin();
}

void loop() {

  int sensorValueX = analogRead(A2);
  int sensorValueY = analogRead(A3);
  if (sensorValueY < 20) {
    Keyboard.press('k');
  
  }else{
    Keyboard.release('k');
  }

  if (sensorValueX < 20) {
    Keyboard.press('l');
  } else{
    Keyboard.release('l');
  }

  if (sensorValueY > 1000) {
    Keyboard.press('i');
  } else{
    Keyboard.release('i');
  }
  if (sensorValueX > 1000) {
    Keyboard.press('j');
  }else {
    Keyboard.release('j');
  }



  if (digitalRead(1) == LOW){
  
    Keyboard.press("KEY_ESC");
  } else{
    Keyboard.release("KEY_ESC");
  }
  if (digitalRead(0) == LOW){
    //Send the message
    Keyboard.press("KEY_LEFT_SHIFT");
  } else{
    Keyboard.release("KEY_LEFT_SHIFT");
  }
    
  if (digitalRead(2) == LOW){
    //Send the message
    Keyboard.press("KEY_LEFT_CTRL");
  } else{
    Keyboard.release("KEY_LEFT_CTRL");
  }
  
  if (digitalRead(3) == LOW){ 
    //Send the message
    Keyboard.press("q");
  } else{
    Keyboard.release("q");
  }
   
  if (digitalRead(4) == LOW){
    //Send the message
    Keyboard.press("a");
  } else{
    Keyboard.release("a");
  }
   
  if (digitalRead(5) == LOW) 
    //Send the message
    {
    Keyboard.press("z");
  } else{
    Keyboard.release("z");
  }
   
  if (digitalRead(6) == LOW){ 
    //Send the message
    Keyboard.press("w");
  } else{
    Keyboard.release("w");
  }
   
  if (digitalRead(7) == LOW){
    //Send the
     Keyboard.press("s");
  } else{
    Keyboard.release("s");
  }
  if (digitalRead(8) == LOW){
    //Send the message
    Keyboard.press("x");
  
  } else{
    Keyboard.release("x");
  }
    
  if (digitalRead(19) == LOW){
    //Send the message
    Keyboard.press("u");
  
    } else{
    Keyboard.release("u");
  }
   
  if (digitalRead(15) == LOW){
    //Send the message
    Keyboard.press("e");
    }else {
    Keyboard.release("e");
  }

  if (digitalRead(14) == LOW){
    //Send the message
    Keyboard.press("d");
  }else {
    Keyboard.release("d");
  }
  
  if (digitalRead(16) == LOW) {
    //Send the messag
    Keyboard.press("c");
    }else {
    Keyboard.release("c");
  }
  


  ///////////////////BUTTON PRESSES//////////////


  delay(50);
}

Does this function really accept a string as a parameter?

    Keyboard.press("KEY_ESC");

perhaps you meant

    Keyboard.press('KEY_ESC');

?

i will try that and get back to you, thanks!

but would that explain why some of the keys outputed different characters?

well...
4e2qoz.jpg

4e2qoz.jpg

The .press() and .release() functions take a single byte, not a string.

    Keyboard.press("KEY_ESC");
  } else{
    Keyboard.release("KEY_ESC");
  }

That should use the bye value with the name KEY_ESC, not the string "KEY_ESC"

    Keyboard.press(KEY_ESC);
  } else{
    Keyboard.release(KEY_ESC);
  }

Didn't you wonder why you got all of these warning messages?

sketch_sep06a.ino: In function 'void loop()':
sketch_sep06a.ino:78:29: warning: invalid conversion from 'const char*' to 'uint8_t {aka unsigned char}' [-fpermissive]
     Keyboard.press("KEY_ESC");
                             ^
In file included from sketch_sep06a.ino:1:0:
/libraries/Keyboard/src/Keyboard.h:106:10: note:   initializing argument 1 of 'size_t Keyboard_::press(uint8_t)'
   size_t press(uint8_t k);
          ^~~~~
sketch_sep06a.ino:82:31: warning: invalid conversion from 'const char*' to 'uint8_t {aka unsigned char}' [-fpermissive]
     Keyboard.release("KEY_ESC");
                               ^
In file included from sketch_sep06a.ino:1:0:
/libraries/Keyboard/src/Keyboard.h:107:10: note:   initializing argument 1 of 'size_t Keyboard_::release(uint8_t)'
   size_t release(uint8_t k);
          ^~~~~~~
sketch_sep06a.ino:87:36: warning: invalid conversion from 'const char*' to 'uint8_t {aka unsigned char}' [-fpermissive]
     Keyboard.press("KEY_LEFT_SHIFT");
                                    ^
In file included from sketch_sep06a.ino:1:0:
/libraries/Keyboard/src/Keyboard.h:106:10: note:   initializing argument 1 of 'size_t Keyboard_::press(uint8_t)'
   size_t press(uint8_t k);
          ^~~~~
sketch_sep06a.ino:91:38: warning: invalid conversion from 'const char*' to 'uint8_t {aka unsigned char}' [-fpermissive]
     Keyboard.release("KEY_LEFT_SHIFT");
                                      ^
In file included from sketch_sep06a.ino:1:0:
/libraries/Keyboard/src/Keyboard.h:107:10: note:   initializing argument 1 of 'size_t Keyboard_::release(uint8_t)'
   size_t release(uint8_t k);
          ^~~~~~~
sketch_sep06a.ino:97:35: warning: invalid conversion from 'const char*' to 'uint8_t {aka unsigned char}' [-fpermissive]
     Keyboard.press("KEY_LEFT_CTRL");
                                   ^
In file included from sketch_sep06a.ino:1:0:
/libraries/Keyboard/src/Keyboard.h:106:10: note:   initializing argument 1 of 'size_t Keyboard_::press(uint8_t)'
   size_t press(uint8_t k);
          ^~~~~
sketch_sep06a.ino:101:37: warning: invalid conversion from 'const char*' to 'uint8_t {aka unsigned char}' [-fpermissive]
     Keyboard.release("KEY_LEFT_CTRL");
                                     ^
In file included from sketch_sep06a.ino:1:0:
/libraries/Keyboard/src/Keyboard.h:107:10: note:   initializing argument 1 of 'size_t Keyboard_::release(uint8_t)'
   size_t release(uint8_t k);
          ^~~~~~~
sketch_sep06a.ino:107:23: warning: invalid conversion from 'const char*' to 'uint8_t {aka unsigned char}' [-fpermissive]
     Keyboard.press("q");
                       ^
In file included from sketch_sep06a.ino:1:0:
/libraries/Keyboard/src/Keyboard.h:106:10: note:   initializing argument 1 of 'size_t Keyboard_::press(uint8_t)'
   size_t press(uint8_t k);
          ^~~~~
sketch_sep06a.ino:111:25: warning: invalid conversion from 'const char*' to 'uint8_t {aka unsigned char}' [-fpermissive]
     Keyboard.release("q");
                         ^
In file included from sketch_sep06a.ino:1:0:
/libraries/Keyboard/src/Keyboard.h:107:10: note:   initializing argument 1 of 'size_t Keyboard_::release(uint8_t)'
   size_t release(uint8_t k);
          ^~~~~~~
sketch_sep06a.ino:117:23: warning: invalid conversion from 'const char*' to 'uint8_t {aka unsigned char}' [-fpermissive]
     Keyboard.press("a");
                       ^
In file included from sketch_sep06a.ino:1:0:
/libraries/Keyboard/src/Keyboard.h:106:10: note:   initializing argument 1 of 'size_t Keyboard_::press(uint8_t)'
   size_t press(uint8_t k);
          ^~~~~
sketch_sep06a.ino:121:25: warning: invalid conversion from 'const char*' to 'uint8_t {aka unsigned char}' [-fpermissive]
     Keyboard.release("a");
                         ^
In file included from sketch_sep06a.ino:1:0:
/libraries/Keyboard/src/Keyboard.h:107:10: note:   initializing argument 1 of 'size_t Keyboard_::release(uint8_t)'
   size_t release(uint8_t k);
          ^~~~~~~
sketch_sep06a.ino:127:23: warning: invalid conversion from 'const char*' to 'uint8_t {aka unsigned char}' [-fpermissive]
     Keyboard.press("z");
                       ^
In file included from sketch_sep06a.ino:1:0:
/libraries/Keyboard/src/Keyboard.h:106:10: note:   initializing argument 1 of 'size_t Keyboard_::press(uint8_t)'
   size_t press(uint8_t k);
          ^~~~~
sketch_sep06a.ino:131:25: warning: invalid conversion from 'const char*' to 'uint8_t {aka unsigned char}' [-fpermissive]
     Keyboard.release("z");
                         ^
In file included from sketch_sep06a.ino:1:0:
/libraries/Keyboard/src/Keyboard.h:107:10: note:   initializing argument 1 of 'size_t Keyboard_::release(uint8_t)'
   size_t release(uint8_t k);
          ^~~~~~~
sketch_sep06a.ino:137:23: warning: invalid conversion from 'const char*' to 'uint8_t {aka unsigned char}' [-fpermissive]
     Keyboard.press("w");
                       ^
In file included from sketch_sep06a.ino:1:0:
/libraries/Keyboard/src/Keyboard.h:106:10: note:   initializing argument 1 of 'size_t Keyboard_::press(uint8_t)'
   size_t press(uint8_t k);
          ^~~~~
sketch_sep06a.ino:141:25: warning: invalid conversion from 'const char*' to 'uint8_t {aka unsigned char}' [-fpermissive]
     Keyboard.release("w");
                         ^
In file included from sketch_sep06a.ino:1:0:
/libraries/Keyboard/src/Keyboard.h:107:10: note:   initializing argument 1 of 'size_t Keyboard_::release(uint8_t)'
   size_t release(uint8_t k);
          ^~~~~~~
sketch_sep06a.ino:147:23: warning: invalid conversion from 'const char*' to 'uint8_t {aka unsigned char}' [-fpermissive]
     Keyboard.press("s");
                       ^
In file included from sketch_sep06a.ino:1:0:
/libraries/Keyboard/src/Keyboard.h:106:10: note:   initializing argument 1 of 'size_t Keyboard_::press(uint8_t)'
   size_t press(uint8_t k);
          ^~~~~
sketch_sep06a.ino:151:25: warning: invalid conversion from 'const char*' to 'uint8_t {aka unsigned char}' [-fpermissive]
     Keyboard.release("s");
                         ^
In file included from sketch_sep06a.ino:1:0:
/libraries/Keyboard/src/Keyboard.h:107:10: note:   initializing argument 1 of 'size_t Keyboard_::release(uint8_t)'
   size_t release(uint8_t k);
          ^~~~~~~
sketch_sep06a.ino:156:23: warning: invalid conversion from 'const char*' to 'uint8_t {aka unsigned char}' [-fpermissive]
     Keyboard.press("x");
                       ^
In file included from sketch_sep06a.ino:1:0:
/libraries/Keyboard/src/Keyboard.h:106:10: note:   initializing argument 1 of 'size_t Keyboard_::press(uint8_t)'
   size_t press(uint8_t k);
          ^~~~~
sketch_sep06a.ino:161:25: warning: invalid conversion from 'const char*' to 'uint8_t {aka unsigned char}' [-fpermissive]
     Keyboard.release("x");
                         ^
In file included from sketch_sep06a.ino:1:0:
/libraries/Keyboard/src/Keyboard.h:107:10: note:   initializing argument 1 of 'size_t Keyboard_::release(uint8_t)'
   size_t release(uint8_t k);
          ^~~~~~~
sketch_sep06a.ino:167:23: warning: invalid conversion from 'const char*' to 'uint8_t {aka unsigned char}' [-fpermissive]
     Keyboard.press("u");
                       ^
In file included from sketch_sep06a.ino:1:0:
/libraries/Keyboard/src/Keyboard.h:106:10: note:   initializing argument 1 of 'size_t Keyboard_::press(uint8_t)'
   size_t press(uint8_t k);
          ^~~~~
sketch_sep06a.ino:172:25: warning: invalid conversion from 'const char*' to 'uint8_t {aka unsigned char}' [-fpermissive]
     Keyboard.release("u");

Sketch uses 6600 bytes (23%) of program storage space. Maximum is 28672 bytes.
Global variables use 280 bytes (10%) of dynamic memory, leaving 2280 bytes for local variables. Maximum is 2560 bytes.

I think what happens is, a pointer to the constant string that you used, is truncated to a char and used as a character. Pointers can point almost anywhere, so the truncated byte has an essentially random value, as far as character meaning is concerned.

johnwasser:
The .press() and .release() functions take a single byte, not a string.

    Keyboard.press("KEY_ESC");

} else{
    Keyboard.release("KEY_ESC");
  }




That should use the bye value with the name KEY_ESC, not the string "KEY_ESC"


Keyboard.press(KEY_ESC);
  } else{
    Keyboard.release(KEY_ESC);
  }




Didn't you wonder why you got all of these warning messages?



sketch_sep06a.ino: In function 'void loop()':
sketch_sep06a.ino:78:29: warning: invalid conversion from 'const char*' to 'uint8_t {aka unsigned char}' [-fpermissive]
    Keyboard.press("KEY_ESC");
                            ^
In file included from sketch_sep06a.ino:1:0:
/libraries/Keyboard/src/Keyboard.h:106:10: note:  initializing argument 1 of 'size_t Keyboard_::press(uint8_t)'
  size_t press(uint8_t k);
          ^~~~~
sketch_sep06a.ino:82:31: warning: invalid conversion from 'const char*' to 'uint8_t {aka unsigned char}' [-fpermissive]
    Keyboard.release("KEY_ESC");
                              ^
In file included from sketch_sep06a.ino:1:0:
/libraries/Keyboard/src/Keyboard.h:107:10: note:  initializing argument 1 of 'size_t Keyboard_::release(uint8_t)'
  size_t release(uint8_t k);
          ^~~~~~~
sketch_sep06a.ino:87:36: warning: invalid conversion from 'const char*' to 'uint8_t {aka unsigned char}' [-fpermissive]
    Keyboard.press("KEY_LEFT_SHIFT");
                                    ^
In file included from sketch_sep06a.ino:1:0:
/libraries/Keyboard/src/Keyboard.h:106:10: note:  initializing argument 1 of 'size_t Keyboard_::press(uint8_t)'
  size_t press(uint8_t k);
          ^~~~~
sketch_sep06a.ino:91:38: warning: invalid conversion from 'const char*' to 'uint8_t {aka unsigned char}' [-fpermissive]
    Keyboard.release("KEY_LEFT_SHIFT");
                                      ^
In file included from sketch_sep06a.ino:1:0:
/libraries/Keyboard/src/Keyboard.h:107:10: note:  initializing argument 1 of 'size_t Keyboard_::release(uint8_t)'
  size_t release(uint8_t k);
          ^~~~~~~
sketch_sep06a.ino:97:35: warning: invalid conversion from 'const char*' to 'uint8_t {aka unsigned char}' [-fpermissive]
    Keyboard.press("KEY_LEFT_CTRL");
                                  ^
In file included from sketch_sep06a.ino:1:0:
/libraries/Keyboard/src/Keyboard.h:106:10: note:  initializing argument 1 of 'size_t Keyboard_::press(uint8_t)'
  size_t press(uint8_t k);
          ^~~~~
sketch_sep06a.ino:101:37: warning: invalid conversion from 'const char*' to 'uint8_t {aka unsigned char}' [-fpermissive]
    Keyboard.release("KEY_LEFT_CTRL");
                                    ^
In file included from sketch_sep06a.ino:1:0:
/libraries/Keyboard/src/Keyboard.h:107:10: note:  initializing argument 1 of 'size_t Keyboard_::release(uint8_t)'
  size_t release(uint8_t k);
          ^~~~~~~
sketch_sep06a.ino:107:23: warning: invalid conversion from 'const char*' to 'uint8_t {aka unsigned char}' [-fpermissive]
    Keyboard.press("q");
                      ^
In file included from sketch_sep06a.ino:1:0:
/libraries/Keyboard/src/Keyboard.h:106:10: note:  initializing argument 1 of 'size_t Keyboard_::press(uint8_t)'
  size_t press(uint8_t k);
          ^~~~~
sketch_sep06a.ino:111:25: warning: invalid conversion from 'const char*' to 'uint8_t {aka unsigned char}' [-fpermissive]
    Keyboard.release("q");
                        ^
In file included from sketch_sep06a.ino:1:0:
/libraries/Keyboard/src/Keyboard.h:107:10: note:  initializing argument 1 of 'size_t Keyboard_::release(uint8_t)'
  size_t release(uint8_t k);
          ^~~~~~~
sketch_sep06a.ino:117:23: warning: invalid conversion from 'const char*' to 'uint8_t {aka unsigned char}' [-fpermissive]
    Keyboard.press("a");
                      ^
In file included from sketch_sep06a.ino:1:0:
/libraries/Keyboard/src/Keyboard.h:106:10: note:  initializing argument 1 of 'size_t Keyboard_::press(uint8_t)'
  size_t press(uint8_t k);
          ^~~~~
sketch_sep06a.ino:121:25: warning: invalid conversion from 'const char*' to 'uint8_t {aka unsigned char}' [-fpermissive]
    Keyboard.release("a");
                        ^
In file included from sketch_sep06a.ino:1:0:
/libraries/Keyboard/src/Keyboard.h:107:10: note:  initializing argument 1 of 'size_t Keyboard_::release(uint8_t)'
  size_t release(uint8_t k);
          ^~~~~~~
sketch_sep06a.ino:127:23: warning: invalid conversion from 'const char*' to 'uint8_t {aka unsigned char}' [-fpermissive]
    Keyboard.press("z");
                      ^
In file included from sketch_sep06a.ino:1:0:
/libraries/Keyboard/src/Keyboard.h:106:10: note:  initializing argument 1 of 'size_t Keyboard_::press(uint8_t)'
  size_t press(uint8_t k);
          ^~~~~
sketch_sep06a.ino:131:25: warning: invalid conversion from 'const char*' to 'uint8_t {aka unsigned char}' [-fpermissive]
    Keyboard.release("z");
                        ^
In file included from sketch_sep06a.ino:1:0:
/libraries/Keyboard/src/Keyboard.h:107:10: note:  initializing argument 1 of 'size_t Keyboard_::release(uint8_t)'
  size_t release(uint8_t k);
          ^~~~~~~
sketch_sep06a.ino:137:23: warning: invalid conversion from 'const char*' to 'uint8_t {aka unsigned char}' [-fpermissive]
    Keyboard.press("w");
                      ^
In file included from sketch_sep06a.ino:1:0:
/libraries/Keyboard/src/Keyboard.h:106:10: note:  initializing argument 1 of 'size_t Keyboard_::press(uint8_t)'
  size_t press(uint8_t k);
          ^~~~~
sketch_sep06a.ino:141:25: warning: invalid conversion from 'const char*' to 'uint8_t {aka unsigned char}' [-fpermissive]
    Keyboard.release("w");
                        ^
In file included from sketch_sep06a.ino:1:0:
/libraries/Keyboard/src/Keyboard.h:107:10: note:  initializing argument 1 of 'size_t Keyboard_::release(uint8_t)'
  size_t release(uint8_t k);
          ^~~~~~~
sketch_sep06a.ino:147:23: warning: invalid conversion from 'const char*' to 'uint8_t {aka unsigned char}' [-fpermissive]
    Keyboard.press("s");
                      ^
In file included from sketch_sep06a.ino:1:0:
/libraries/Keyboard/src/Keyboard.h:106:10: note:  initializing argument 1 of 'size_t Keyboard_::press(uint8_t)'
  size_t press(uint8_t k);
          ^~~~~
sketch_sep06a.ino:151:25: warning: invalid conversion from 'const char*' to 'uint8_t {aka unsigned char}' [-fpermissive]
    Keyboard.release("s");
                        ^
In file included from sketch_sep06a.ino:1:0:
/libraries/Keyboard/src/Keyboard.h:107:10: note:  initializing argument 1 of 'size_t Keyboard_::release(uint8_t)'
  size_t release(uint8_t k);
          ^~~~~~~
sketch_sep06a.ino:156:23: warning: invalid conversion from 'const char*' to 'uint8_t {aka unsigned char}' [-fpermissive]
    Keyboard.press("x");
                      ^
In file included from sketch_sep06a.ino:1:0:
/libraries/Keyboard/src/Keyboard.h:106:10: note:  initializing argument 1 of 'size_t Keyboard_::press(uint8_t)'
  size_t press(uint8_t k);
          ^~~~~
sketch_sep06a.ino:161:25: warning: invalid conversion from 'const char*' to 'uint8_t {aka unsigned char}' [-fpermissive]
    Keyboard.release("x");
                        ^
In file included from sketch_sep06a.ino:1:0:
/libraries/Keyboard/src/Keyboard.h:107:10: note:  initializing argument 1 of 'size_t Keyboard_::release(uint8_t)'
  size_t release(uint8_t k);
          ^~~~~~~
sketch_sep06a.ino:167:23: warning: invalid conversion from 'const char*' to 'uint8_t {aka unsigned char}' [-fpermissive]
    Keyboard.press("u");
                      ^
In file included from sketch_sep06a.ino:1:0:
/libraries/Keyboard/src/Keyboard.h:106:10: note:  initializing argument 1 of 'size_t Keyboard_::press(uint8_t)'
  size_t press(uint8_t k);
          ^~~~~
sketch_sep06a.ino:172:25: warning: invalid conversion from 'const char*' to 'uint8_t {aka unsigned char}' [-fpermissive]
    Keyboard.release("u");

Sketch uses 6600 bytes (23%) of program storage space. Maximum is 28672 bytes.
Global variables use 280 bytes (10%) of dynamic memory, leaving 2280 bytes for local variables. Maximum is 2560 bytes.

Sketch uses 6494 bytes (22%) of program storage space. Maximum is 28672 bytes.
Global variables use 260 bytes (10%) of dynamic memory, leaving 2300 bytes for local variables. Maximum is 2560 bytes.

i didnt get any errors.

@johnwasser thanks i had to remove the"" that worked, i dont fully understand coding, i think im below basics, i do understand enough to see a few parts but the format part im very lost.

after a few google searches, i had a feeling you would be able to help, and you did,

keep up the great work my man!

jerkwagon:
i didnt get any errors.

True, but you did get a PILE of warnings. The compiler uses warnings to tell you when something you did is technically legal but is the sort of thing that is often a mistake that will give results that you don’t expect.
If you have a sketch that is not doing exactly what you thought you told it to, go to Preferences and make sure that “Compiler warnings:” is set to “All”. When you compile, the warnings will show up in the box below your sketch. Look at every warning and figure out what the compiler is pointing out.