Author Options:

I recently received my rotary encoder led ring from sparkfun, but I'm having trouble programming it. Answered

I'm using an Arduino Uno. I found example code but it involves using a rotary encoder for input, which I don't have and don't intend on buying. Does anyone know how to program it to simply turn all the led's?


The forums are retiring in 2021 and are now closed for new topics and comments.

8 years ago

it's a shift register if I recall. The sample code should look for input from a rotary encoder, which you don't have -- just fake that with a delayed for-loop to feed it a number between 0-16, and shift that out. The funny thing with shift registers is you have to shift bits not bytes, so their example code probably has a way to talk to it. Alternately you could use a 10k pot on an analog input to give you the value to spit out to the shift register. From the example pde:

          Copyright (c) 2011 Mayhew Labs.
          Written by Mark Mayhew

This example shows 3 sequences that are possible on the ring of LEDs around the encoder based on rotation of an encoder.  The 3 sequences are
selected by entering 1, 2, or 3 in the serial command prompt.  The serial window shows the current rotary encoder count.  As the encoder is turned,
the serial display shows a raw count of the rotary encoder's value and the LEDs show a scaled version of the value.  If the button on the rotary
encoder is pushed, the bottom LED will come on.  Each section of code below discusses the process required to do this.

A note on setting the output sequence:
Think of each LED as a single bit in a 16-bit long binary string.  If a bit is 1, the LED is on, if a bit is 0, the LED is off. 
By making a string of ones and zeros, we choose which LEDs to have on and off, and then send this string to the shift register to display it.
For example 1000000000000001 binary (0x8001 in hex) will have the fist and last LEDs on, the rest off. 

Reading the rotary encoder is performed with Oleg's example code:a
from http://www.sparkfun.com/products/10407
(example pde)

So, that main loop keeps checking the encoder and if it changes, it changes the value sent out with the 'shiftout' section.
It spits out in serial whatever the value is for debugging
and listens on serial for 3 different animation styles.

the MOST IMPORTANT part of this example code is:

scaledCounter = map(counter,0,100,0,15);

      //Send the LED output to the shift register
      shiftOut(SDI,CLK,MSBFIRST,(sequence[sequenceNumber][scaledCounter] >> 8));    //High byte first
      shiftOut(SDI,CLK,MSBFIRST,sequence[sequenceNumber][scaledCounter]);           //Low byte second

This takes an input of 0-100, and turns it into 0-16 leds.  Since there are 16 leds, its 2 8 bit bytes, hence it sends the first 8 bits, shifted over by 8, then the last 8 bits, followed by setting the enable pin.

You can use that chunk of code to output any number of leds.  To change the specific bits being changed, change the value of 'scaled counter' with bitwise operations. (look that up).

Answer 8 years ago

thanks, but I still don't understand. Can you give me any code?


Answer 8 years ago


This is 'how' the circuit is designed; just is uses a TI chip instead of a 595, the principle is the same, data clock and latch.

Once you understand shiftout, you can work with your encoder board with ease.


Answer 8 years ago

Thanks, your awesome, it makes alot more sense now but one last question. How do I tell if my board is fried?