Problem with keyboard.h!

Hi there, i have a problem with Keyboard library . I have arduino leonardo. I wrote this code, and keyboard doesn't typing , but function works .

#include <Keyboard.h>
#include <Mouse.h>

bool q = true;
bool w = true;

int sensorValue = 0;

void setup() {
  pinMode(A0, INPUT);

void loop() {
  sensorValue = analogRead(A0);
  if(int(sensorValue) == 1017 && q == true) {'a');
    q = false;
    w = true;
  else if(int(sensorValue) == 77 && w == true) {
    q = true;
    w = false;

Why Keyboard.h doesn't work ? Please help !

Have you tried printing the values returned by analogRead to see if they're what you expect?
I wouldn't use == in this case; better you use a range.

Analogue readings are notoriously noisy.

I printed this values with Serial.print . And values +/- stable . Then i wrote code with this values. I have this thing:

And this thing have fixed positions. All works but not keyboard . I don't know why . Yes ok i rewrite code with using range , but will it fix keyboard ?

Post the schematic of your project with all components used.

Hi there my scheme looks like this

This black scheme on the left side, this is type of connection that i use for my "potentiometer" . This is thing from USSR , and it's like potentiometer with 10 fixed positions , in my build i use only 7 . But i didn't find scheme with 7 buttons (It works like 7 buttons) , only 4 buttons , but you just imagine other 3 buttons and resistors.

And my 7 resistors doen't have the same Ω value .
From first to last -> 1,2KΩ ; 1KΩ ; 1,5KΩ ; 1,1KΩ ; 1KΩ; 1KΩ; 910Ω
And one more resistor connected to GND: 10KΩ

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.