Go Down

### Topic: rotary encoder and shift register (Read 2015 times)previous topic - next topic

##### Dec 29, 2014, 08:17 pm
Hello everyone!

To start a little project I was hoping to get some help so I can learn better and avoid making stupid mistakes.

What I want to do:

Step 1:
A rotary encoder is used as a hand crank to control a strip of 64 single LEDs. For the outputs I use 8 shift register (74HC595). When the encoder rotates about the value x (for example +-50) the next (or previous) LED of the array should be set HIGH (every other LED LOW - so only one LED at a time). Working in both directions. After the LED 64 is reached it starts again with LED 1.

Step 2:
A switch should change the "manual mode" to "automatic mode". For this the sweep effect of the LED array should continue after the hand crank stops rotating. So I need to measure the speed of the rotation (the last 3 seconds?) and then continue this speed automatically.

I'm not sure how to start. So I'm happy for every suggestion I can get.

#1
##### Dec 30, 2014, 04:36 pm
So I decided to work with rounds per minutes. Something like this

Code: [Select]
` encoderValue = 0;  delay(3000);  int rpm = encoderValue/100*20;  Serial.println(rpm);`

But I'm not sure how to handle 8 shift registers. I have to shift out each register with 1,2,4,8,16,32,64 or 128, but how can I convert DEZ 1-64? Do I have to use 8 arrays or is there a better way?

#### boolrules

#2
##### Dec 30, 2014, 06:32 pm
Each rotary change, set previous_time to current_time and set current_time to millis( ).
When the when the switch is thrown, current_time - previous_time is the period used to change the LEDs.
Direction will have to be saved by the rotary code.
If you need to track absolute values of the rotary, I'm not clear how that would be used.

#### Paul__B

#3
##### Dec 31, 2014, 06:25 am
Can possibly give you some code for the "Keep on going", but my main question is - why use lots of shift registers, when a single MAX7219 would easily control 64 LEDs with two capacitors and one resistor?

#4
##### Dec 31, 2014, 02:39 pmLast Edit: Dec 31, 2014, 06:36 pm by multigrade
Because I didn't think of MAX7219. You are right, that would be easier.
But now I already have 8 shift register and they are fitting perfectly on the breadboard .

I was thinking about how to "convert" number 1 to 64 into bytes for the registers. I post my code next.

Go Up