How to Add Keyboard Input to the All-Seeing Eye - dummies

How to Add Keyboard Input to the All-Seeing Eye

By Brock Craft

You can use keyboard input to set the exact time delay value for your all-seeing eye, which controls how fast you want your eye to move back and forth. You can use the same technique to add numerical keyboard input to any of your sketches.

Change the code for your all-seeing eye

Open the code for your all-seeing eye and create a new sketch. Then add the following code:

  1. Create a variable in the variable declaration section to store your input from the keyboard:

    int input;
  2. In the setup() section, create a serial channel on to connect to your Arduino so that you can read from your computer’s keyboard:

  3. Add code to read from the keyboard to the end of your loop, before the last curly bracket:

   while (Serial.available() > 0) {
   input += Serial.parseInt();
   if ( == 'n'){
     timeDelay = input;

How keyboard input works

The speed at which the lights move back and forth is controlled by the variable timeDelay and is set to 40 milliseconds at the top of the sketch. You can change this with keyboard input (only using numbers of course!) to set a new delay time in milliseconds.

The while loop you add to the loop() section of the code checks to see if there has been any new input on the serial port. If so, the new input is added to the integer variable “input”.

The if statement checks to see whether the enter key was pressed. The forward slash and ‘n’ indicates enter. If the sketch detects it, the timeDelay variable is changed to the value that has been stored by the input variable.

The larger the number you type in, the slower your eye will scan back and forth, and vice versa. You could do the same thing any time you want to be able to change a variable with a numeric value entered from the keyboard!

You can simply download the code from the companion website and use it for your project.