source: arduino-1-6-7/trunk/fuentes/arduino-ide-amd64/examples/09.USB/Keyboard/KeyboardMessage/KeyboardMessage.ino @ 4837

Last change on this file since 4837 was 4837, checked in by daduve, 3 years ago

Adding new version

File size: 1.3 KB
Line 
1/*
2 Keyboard Message test
3
4 For the Arduino Leonardo and Micro.
5
6 Sends a text string when a button is pressed.
7
8 The circuit:
9 * pushbutton attached from pin 4 to +5V
10 * 10-kilohm resistor attached from pin 4 to ground
11
12 created 24 Oct 2011
13 modified 27 Mar 2012
14 by Tom Igoe
15 modified 11 Nov 2013
16 by Scott Fitzgerald
17
18 This example code is in the public domain.
19
20 http://www.arduino.cc/en/Tutorial/KeyboardMessage
21 */
22
23#include "Keyboard.h"
24
25const int buttonPin = 4;          // input pin for pushbutton
26int previousButtonState = HIGH;   // for checking the state of a pushButton
27int counter = 0;                  // button push counter
28
29void setup() {
30  // make the pushButton pin an input:
31  pinMode(buttonPin, INPUT);
32  // initialize control over the keyboard:
33  Keyboard.begin();
34}
35
36void loop() {
37  // read the pushbutton:
38  int buttonState = digitalRead(buttonPin);
39  // if the button state has changed,
40  if ((buttonState != previousButtonState)
41      // and it's currently pressed:
42      && (buttonState == HIGH)) {
43    // increment the button counter
44    counter++;
45    // type out a message
46    Keyboard.print("You pressed the button ");
47    Keyboard.print(counter);
48    Keyboard.println(" times.");
49  }
50  // save the current button state for comparison next time:
51  previousButtonState = buttonState;
52}
53
Note: See TracBrowser for help on using the repository browser.