rotary encoder code

hi

I’ve got this code but when i move my encoder CW or CCW it gives me a continuous keyboard print but i only want it to give me it once

#include <Encoder.h>
#include <Keyboard.h>
//
Encoder myEnc(2, 3);

void setup() 
{
  Serial.begin(9600);
  Serial.println("Basic Encoder Test:");
}


long oldPosition  = -999;

void loop() 
{
  long newPosition = myEnc.read();
  if (newPosition != oldPosition) 
  {
    oldPosition = newPosition;
    Serial.println(newPosition);
  }
  {
    analogRead(newPosition); 
    if (newPosition <= -3)
      {
        Keyboard.print("p");
      }
    else if (newPosition < 2 && newPosition > -2)
      {
      }
    else if (newPosition >= 3)
      {
        Keyboard.print("i");
      }
  }
}

Drop the code starting with analogRead(), it's crap.

Think twice about what you want :-]

You get a single output if you move the output code into setup(). Afterwards you can turn the encoder as you like, without any further output.

For more meaningful output you should specify at which exact event an output should occur.