Pages: [1]   Go Down
Author Topic: Mayhew rotary encoder LED ring  (Read 1372 times)
0 Members and 1 Guest are viewing this topic.
UK
Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So I got a Mayhew Labs rotary encoder LED ring, and I'm intending to use it to indicate an internal value on my Arduino Nano as part of a GPS project I'm working on. I've seen a bunch of videos displaying that you don't need a mounted potentiometer to use this chip, but I've yet to replicate their effects at all.

Currently, I have a blue LED ring mounted to the Nano as such:
  • GND to GND
  • VCC to 5V
  • ENCA, ENCB, and SWITCH are not used
  • SDI to D2
  • CLK to D3
  • LE to D4
  • OE and SDO are not used
The Nano and LED ring are fresh out of the box, untampered with and multimeter readings support that they're working fine. The Nano is running the following code for testing purposes, modified from a Mayhew example code for the chip to remove the potentiometer from the mix:
Code:
//These are the pins that will talk to the shift register through SPI
#define SDI    2    //Data
#define CLK    3    //Clock
#define LE     4    //Latch

// Global variables
int sequenceNumber;   //The output sequence for the LEDs
int Cap = 15;
int counter = 5;
int inc = 1;

unsigned int sequence[3][16] = {
            {0x0,0x1,0x2,0x4,0x8,0x10,0x20,0x40,0x80,0x100,0x200,0x400,0x800,0x1000,0x2000,0x4000},
            {0x0,0x1,0x3,0x7,0xf,0x1f,0x3f,0x7f,0xff,0x1ff,0x3ff,0x7ff,0xfff,0x1fff,0x3fff,0x7fff},
            {0x0,0x7fff,0x3ffe,0x1ffc,0xff8,0x7f0,0x3e0,0x1c0,0x80,0x1c0,0x3e0,0x7f0,0xff8,0x1ffC,0x3ffe,0x7fff},
                               };

void setup()
{
  //Set SPI pins to output
  pinMode(SDI, OUTPUT);
  pinMode(CLK, OUTPUT);
  pinMode(LE,OUTPUT);
  //Set serial rate, prompt for desired sequence
  Serial.begin(9600);
  Serial.println("Enter 1, 2, or 3 to change the LED sequence");
}


void loop()
{
  //Get any serial input
  if (Serial.available() > 0) {
    int incomingByte = Serial.read();
   
    if (incomingByte == '1') {
      sequenceNumber=0;
      Serial.println("Sequence 1 selected!");
    }
    if (incomingByte == '2') {
      sequenceNumber=1;
      Serial.println("Sequence 2 selected!");
    }
    if (incomingByte == '3') {
      sequenceNumber=2;
      Serial.println("Sequence 3 selected!");
    }
  }
 
  if(sequenceNumber >= 0) {   
    if(counter >= 15 || counter <= 1){
      inc *= -1;
    }
    counter += inc;
   
    int scaledCounter = map(counter, 0, Cap, 0, 15);
   
    //Send the LED output to the shift register
    digitalWrite(LE,LOW);
      shiftOut(SDI,CLK,MSBFIRST,(sequence[sequenceNumber][scaledCounter] >> 8));    //High byte first
      shiftOut(SDI,CLK,MSBFIRST,sequence[sequenceNumber][scaledCounter]);           //Low byte second
    digitalWrite(LE,HIGH);
  }
  delay(500);
}
Logged

Offline Offline
Jr. Member
**
Karma: 9
Posts: 79
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

OE needs to attach to ground.
Logged

Pages: [1]   Go Up
Jump to: