Do you have decoupling caps on the data pins of the encoder ?
It was mentioned in several comments that this would happen without them.
The KY040 module contains a rotary encoder together with a push-switch on a small
' PCB with 5 Connections. The KY040 was developed for Arduino, but of course us uMite
' folk can use it as well, and the KY040 is incredibly cheap, US$2.0 inc P&P, just
' search eBay for KY040.
'
' Wiring it up
'
' KY040 Micromite
' ----- ---------
' CLK 2 ---> 0.1uF ---> Ov
' DT 3 ---> 0.1uF ---> Ov
' SW 4 ---> 0.1uF ---> Ov
' + 3V3
' Gnd 0V
'
' NB
' 1) It is VERY important to decouple the DT,CLK & SW pins to 0V
**' using 0.1uF at the uMite end of the link wire. **
' If you don't decouple these signals, severe contact bounce will be evident,
' eg one click will generate a dozen or more increment/decrements.
'
' 2) The KY040 module has on-board pullup resistors. You must supply 3V3 or less
' to the + pin of the KY040 module
'
' 3) This s/w works fine with just a standalone rotary encoder, but you will need
' to supply your own 10K pullups to 3V3. For a standalone encoder RA=CLK, RB=DT, & SW=SW
'
' When this software runs, each CLOCKwise step of the rotary encoder will result
' in an increase of the variable DisplayValue which will be printed to the Console.
' Each ANTI-clockwise step of the rotary encoder will result in a decrease of the
' variable DisplayValue which will be printed to the Console.
' Pushing the push-switch will clear the variable DisplayValue to 0.