Need help for my Sketch

Using Arduino Leonardo. This sketch works.

=============
#include "Keyboard.h"

void setup() {
pinMode(13, INPUT);
Keyboard.begin();
}

void loop() {
digitalWrite(13, HIGH);
Keyboard.press("1");
delay(1000);

digitalWrite(13, LOW);
Keyboard.press("0");
delay(1000);

}

Keyboard.press ("1")

sends to the PC the number 1 and

Keyboard.press ("0") sends to the PC the

number 0.

I wish they would send to the PC the number

2 instead of the number 1.

How can I change the sketch?

Thanks

Keyboard.press ('2');

(Edited to replace " with ')

Also writing Keyboard.press (“2”); on the PC always displays 1

Seeing is believing!

How to edit the sketch?

Thanks

Hi lupiana,

I think you want to call Keyboard.print or .println instead of .press

Or replace the " in the press call with '

Try that first.

Pat

Hi patduino,

your solution don't work.

I try to explain better:

I want to turn on 3 LEDs and after each with delay (1000) bring it back to LOW and turn on the next.

When the first LED is HIGH want to send to the PC the number "1", when the second LED is HIGH want to send to the PC the number "2", When the third LED is HIGH want to send to the PC the number "0".

The sketch please.

Thanks

If you expect to get fully working solutions on this (or probably any) forum, then you have at least to specify your requirements much more accurately that you have.
As background information, you could also present your project and what you are trying to achieve to get optimal help here.
If you are relatively new to Arduino programming, then you may also benefit from buying an Arduino Starter and working through some of the example projects there.

Either that or indicate that you are willing to pay for a completed solution. In that case you’ll probably find that someone is more willing to engage one-on-one to get you something that works properly without having to guess at what you need.

Or explain in Italian, maybe google translator is better:

O spiegare in italiano , forse Google Translator è meglio.

lupiana:
Hi patduino,
your solution don't work.

His solution did what you said it should do, but what you said was not what you wanted. This is not the same thing as Patduinos's sketch not working.

lupiana:
I want to turn on 3 LEDs and after each with delay (1000) bring it back to LOW and turn on the next. When the first LED is HIGH want to send to the PC the number "1", when the second LED is HIGH want to send to the PC the number "2", When the third LED is HIGH want to send to the PC the number "0".

I'll assume your LEDs are on pins 13,12, and 11.

void loop() {
  turn_on_a_LED_and_send_a_key(13, "1");
  turn_on_a_LED_and_send_a_key(12, "2");
  turn_on_a_LED_and_send_a_key(11, "0");
}

void turn_on_a_LED_and_send_a_key(byte LED, char * KEY) {
  digitalWrite(LED, HIGH);   
  Keyboard.press(KEY); 
  delay(1000);             
  digitalWrite(LED, LOW);   
}

Your sketch sketch for what Arduino? One or Leonardo?

Should I put some library?

Thanks

lupiana:
Your sketch sketch for what Arduino? One or Leonardo?

My post was not a complete sketch, it was just the loop(). A complete sketch will also need your setup() function to set up the pins and keyboard.

Please a complete sketch.

Thank you very much.