Go Down

### Topic: Adjusting digits in a number using a rotary encoder (Read 630 times)previous topic - next topic

#### TechBoyInventor

##### Apr 13, 2018, 12:07 am
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

#### Grumpy_Mike

#1
##### Apr 13, 2018, 12:50 am
What sort of display have you got?
Basically use the rotary encoder example and feed the output number to your display.

#### TechBoyInventor

#2
##### Apr 13, 2018, 01:35 am
I am using an Adafruit 3.5 inch tft and am trying to adjust the individual digits of a number from 0 to 9.

#### dougp

#3
##### Apr 13, 2018, 04:24 am
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.

Everything we call real is made of things that cannot be regarded as real.  If quantum mechanics hasn't profoundly shocked you, you haven't understood it yet. - Niels Bohr

No private consultations undertaken!

#### TechBoyInventor

#4
##### Apr 13, 2018, 07:48 pm
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

#### dougp

#5
##### Apr 13, 2018, 09:16 pm
Does the encoder include the mentioned integral switch?
Everything we call real is made of things that cannot be regarded as real.  If quantum mechanics hasn't profoundly shocked you, you haven't understood it yet. - Niels Bohr

No private consultations undertaken!

#### TechBoyInventor

#6
##### Apr 13, 2018, 10:27 pm
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.

#### Grumpy_Mike

#7
##### Apr 13, 2018, 10:44 pm
Quote
It has 5 pins and one of them is  a switch.
If it only has 5 pins then there is no switch.

#### dougp

#8
##### Apr 13, 2018, 10:49 pm
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.
Everything we call real is made of things that cannot be regarded as real.  If quantum mechanics hasn't profoundly shocked you, you haven't understood it yet. - Niels Bohr

No private consultations undertaken!

#### dougp

#9
##### Apr 13, 2018, 10:54 pm
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.
Everything we call real is made of things that cannot be regarded as real.  If quantum mechanics hasn't profoundly shocked you, you haven't understood it yet. - Niels Bohr

No private consultations undertaken!

#### TechBoyInventor

#10
##### Apr 13, 2018, 11:05 pm
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

#### dougp

#11
##### Apr 14, 2018, 02:43 am
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.
Everything we call real is made of things that cannot be regarded as real.  If quantum mechanics hasn't profoundly shocked you, you haven't understood it yet. - Niels Bohr

No private consultations undertaken!

Go Up