902Views5Replies
I recently received my rotary encoder led ring from sparkfun, but I'm having trouble programming it.
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?
Discussions
8 years ago
/*
Rotary_Encoder_LED_Ring_Example
www.mayhewlabs.com/products/rotary-encoder-led-ring
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.
CREDIT:
Reading the rotary encoder is performed with Oleg's example code:a
http://www.circuitsathome.com/mcu/reading-rotary-encoder-on-arduino
*/
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:
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
http://www.arduino.cc/en/Tutorial/ShiftOut
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?