Pages: [1]   Go Down
Author Topic: Arduino Leonardo as Keyboard ???  (Read 303 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 48
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Gang

I've been playing with my Arduino Leonardo and have noticed something odd. I've been specifically working with the keyboard libraries. After uploading the following sketch;

Code:
/*
 Keyboard Button test
 
 For the Arduino Leonardo and Micro.
 
 Sends a text string when a button is pressed.
 
 The circuit:
 * pushbutton attached from pin 2 to +5V
 * 10-kilohm resistor attached from pin 4 to ground
 
 created 24 Oct 2011
 modified 27 Mar 2012
 by Tom Igoe
 
 This example code is in the public domain.
 
 http://www.arduino.cc/en/Tutorial/KeyboardButton
 */

const int buttonPin = 2;          // input pin for pushbutton
int previousButtonState = HIGH;   // for checking the state of a pushButton
int counter = 0;                  // button push counter

void setup() {
  // make the pushButton pin an input:
  pinMode(buttonPin, INPUT);
  // initialize control over the keyboard:
  Keyboard.begin();
}

void loop() {
  // read the pushbutton:
  int buttonState = digitalRead(buttonPin);
  // if the button state has changed,
  if ((buttonState != previousButtonState)
    // and it's currently pressed:
  && (buttonState == HIGH)) {
    // increment the button counter
    counter++;
    // type out a message
    Keyboard.print("You pressed the button ");
    Keyboard.print(counter);
    Keyboard.println(" times.");
  }
  // save the current button state for comparison next time:
  previousButtonState = buttonState;
}

I was hoping that when I plugged the Arduino Leonardo back into the computer it would be viewed as a keyboard. Instead I keep getting prompted with the message;

Found New Hardware
Arduino Leonardo

In contrast using the Teensy 2.0 I don't get this message at all. It's just viewed as external keyboard.

Is there any way to prevent this?

Cheers

Jase
Logged

Pages: [1]   Go Up
Jump to: