Adjusting digits in a number using a rotary encoder

Hi, I am making project, and I need to be able to adjust digits in a number using a rotary encoder. I am unsure on how to do it because I cannot find any good references. Do any of you have an idea on how you could highlight a number using a rotary encoder by clicking on it and then scrolling through the digits and clicking on one that you can adjust from 0 to 9.

thanks,

TechBoy

What sort of display have you got?
Basically use the rotary encoder example and feed the output number to your display.

I am using an Adafruit 3.5 inch tft and am trying to adjust the individual digits of a number from 0 to 9.

TechBoyInventor:
I am using an Adafruit 3.5 inch tft and am trying to adjust the individual digits of a number from 0 to 9.

A very rough outline might be:

Build a function which uses the encoder to select a digit to be operated on. This would imply that each digit of the number is held in - or can be broken out into - its own variable.

If the encoder has an integral switch use that to toggle to a mode which

uses a different function to increment/decrement the selected digit.

when mode is switched back you can do something like -

number = 1s digit + 10s digit * 10 + 100s digit * 100, etc.

Read up on arrays.

I am a bit confused. Is there anyway you could describe the procedure in a little more detail. I am not the best at coding.

thanks,

TechBoy

Does the encoder include the mentioned integral switch?

Yes, I think it does. It is the rotary encoder breakout from a 37 sensor kit. It has 5 pins and one of them is a switch.

It has 5 pins and one of them is a switch.

If it only has 5 pins then there is no switch.

If you haven't already, look over and run the IDE examples: file/examples/digital/button, digitalinputpullup, debouncing, and stateChangeDetection. Take the time and effort to understand what is going on in these sketches, it's a lot of the foundation for further Arduino progress and learning.

Starting from where you, apparently, are you're not going to be able to just throw together a working program. It's a building block process. Understand the elementary principles (like state change detection) well enough to tweak the examples to your need, add in one new part at a time and make it play well with previous parts. Lather, rinse, repeat.

Grumpy_Mike:
If it only has 5 pins then there is no switch.

Mine has five pins and **two ** of them are pushbutton contacts. The remaining three are A, B, and common for the quadrature signal.

Here is a link to a picture of the one I am using.

I have got it working to increase or decrease a variable on the tft. However, for what I am doing I have to edit the individual digits of a number. I am thinking I would need to at first highlight the variable, then if I click the rotary encoder it would highlight one of the digits. I could scroll across the digits by moving the encoder and then when I find the digit I want to edit. I would click on it and I could scroll from 0 to 9. Them click the encoder and it would save the change.

I found an example of it in a video. In this video the person is setting a voltage by editing the individual digits.

Does anyone know how you could code this with an arduino, tft, and a rotary encoder that has a built in swtich.

thanks,

TechBoy

Since you can change a variable with the encoder, make yourself an array of, say three bytes. They will have indices of 0-2. Limit your encoder-controlled digit variable to these numbers. When digit 3 (index 2), for example, is selected switch to digit vary mode with the encoder pushbutton.

In this mode the encoder varies the array member selected in the digit select mode. When the digit is at the desired value, switch out of digit vary mode and update the actual variable by some means as described in post #3.