Close

Software Rotary Encoder

A project log for Arduino Enigma Machine Simulator

An Enigma Machine Simulator was created with an Arduino UNO and a Touchscreen LCD. Simulates Enigma I, M3, M4, the Plugboard and Uhr Switch.

arduino-enigmaArduino Enigma 07/12/2015 at 03:580 Comments

The algorithm for translating a circular movement into incrementing or decrementing a setting is described below.

http://arduinoenigma.blogspot.com/2014/10/implementing-rotary-encoders-in-touch.html

The rotary encoder algorithm uses the pithagorean theorem, to calculate C, the distance from the current click coordinates (clickX,clickY) to the center of the circle (cX,cY).

http://betterexplained.com/articles/measure-any-distance-with-the-pythagorean-theorem/

If the distance C is between the minimum and maximum radius accepted, then another algorithm compares (clickX,clickY) with the X,Y coordinates received the last time the function was called. The distance from the current (clickX,clickY) to the previous (clickX,clickY) is computed using pithagoras and then both coordinates are sent to a series of decision functions to see if this distance is going to be used to increment the step counter or decrement it.

A series of voting functions then look at changes in the X or Y coordinates to determine in a robust manner whether the user motion will increment or decrement the desired setting.

This results in the user being able to drag along the perimeter of a circular control in a clockwise or counterclockwise motion to change it.

Discussions