Learn Arduino with Olympia Circuits
Learn Arduino
  • Home
    • Get Started
    • How to Use This Site
  • Electronics
    • The Basics
    • Electricity Flows like Water
    • Electronic Components
    • The Arno Board
  • Programming
    • The Basics
    • setup and loop Blocks
    • Variables and Arrays
    • Connecting with the Pins
    • Flow Control >
      • if Statement
      • Loops
      • Delays
    • Functions
    • Serial Communication
    • USB
    • Some Thoughts
  • Projects
    • Projects 1 >
      • 1.01: Blink
      • 1.02 Blink x2
      • 1.03 Blink Faster
      • 1.04 LED Chase!
      • 1.05 Wait To Blink
      • 1.06 Blink a Little Faster Now
      • 1.07 LED Fade
      • 1.08 RGB Blink
      • 1.09 Change RGB Color with SW1
      • 1.10 Fade RGB Colors
      • 1.11 Reaction Time Game
    • Projects 2 >
      • 2.01 Hello World
      • 2.02 Talk Back
      • 2.03 ASCII Values
      • 2.04 Ski Game
      • 2.05 Demonstration of the String Object
    • Projects 3 >
      • 3.01 Read the Potentiometer
      • 3.02 ASCIIbet Soup
      • 3.03 Potentiometer sets LED Brightness
      • 3.04 Potentiometer Sets Blink Rate
      • 3.05 LED Chase, Part II
    • Projects 4 >
      • 4.01 Bringing the Piezo to Life
      • 4.02 Controlling the Piezo with a Function
      • 4.03 Piezo C Major
      • 4.04 Piezo Greensleaves
      • 4.05 Piezo Metronome
      • 4.06 Piezo as an Input
      • 4.07 Piezo as an Input 2
      • 4.08 Metronome II
      • 4.09 Piezo Playback
      • 4.10 Piezo Fireworks
      • 4.11 Piezo Mosquito
    • Projects 5 >
      • 5.01 The Phototransistor
      • 5.02 Light and Sound
      • 5.03 Light and Sound II
    • Projects 6 >
      • 6.01 EEPROM
      • 6.02 I2C Address Scan
      • 6.03 Read the I2C Temperature Sensor
      • 6.04 High Temperature Alarm
    • Projects 7 >
      • 7.01 Arno Phone Home
      • 7.02 Keyboard Alphabet
      • 7.03 Move Mouse
      • 7.04 Draw Squares
    • Special Projects >
      • Bike Light Demo
  • References
    • Arno Pin Key
    • Arno Schematic
    • Project Index

Project 7.02 Keyboard Alphabet

Let’s have more fun with the Keyboard object.  Upload this sketch and open a word processor or Notepad.  Click on the page and then press SW1. The Arno will first type out the alphabet in upper case letters.  It then takes advantage of special keyboard characters to replace the upper-case with lower-case letters.

Concepts: ASCII table, Keyboard object

Circuits:     
  • Circuit 2


  • Select Sketch

    ///////////////////////////////////////////////////
    //Project 7.02 Keyboard Alphabet
    char aChar;
    int SW1 = 1;
    void setup(){
    Keyboard.begin();
    pinMode(SW1,INPUT);
    }
    void loop(){
    if(digitalRead(SW1)==LOW){
    for(int x = 65; x< 91; x++){
    aChar = x;
    Keyboard.write(aChar);
    delay(100);
    }
    for(int x = 122; x > 96; x--){
    Keyboard.write(KEY_BACKSPACE);
    aChar = x;
    Keyboard.write(aChar);
    Keyboard.write(KEY_LEFT_ARROW);
    delay(100);
    }
    }
    }
    ///////////////////////////////////////////////////

    We create an instance of the Keyboard object in the setup() block:

      Keyboard.begin();

    The upper-case letters of the alphabet start with the ASCII number 65 and run through 90.  We increment through these letters with a for loop:

        for(int x = 65; x< 91; x++){

    We use the variable aChar to cast x to a char variable.  It’s then sent to the PC as if the character was typed on the keyboard.  We use a short delay to space out the typing:

          aChar = x;

          Keyboard.write(aChar);

          delay(100);

        }

    The lowercase letters in the ASCII table run from 97 to 122.  We run through these backwards:

    for(int x = 122; x > 96; x--){

    To replace the uppercase letter, we first send a backspace and then send the new character:

          Keyboard.write(KEY_BACKSPACE);

          aChar = x;

          Keyboard.write(aChar);

    To position the cursor for the next character, we send a left-arrow key and then move back to the top of the for loop:

          Keyboard.write(KEY_LEFT_ARROW);

          delay(100);

        }

    Back to Projects 7

    Copyright Olympia Circuits LLC 2014. All Rights Reserved.