Problem with writing code for Light project.

Dear forum members.

My name is Bas de Boer. Love using arduino and making projects with it. Only this time i have a little problem with the code.

I’m making analog RGB strips light to my bedroom. And i want to use 2 rotary encoders and 2 switches for 2 RGB strips. One encoder and switch for one strip

The project is like this;

With the encoders i wan’t select the colors of the RGB led strips. One encoder and one switch ( to make color swirl ) vor each strip.

I have problems with making the code. I have a piece of code that works with one encoder and no color swirl.
( The code for 1 rotary encoder );

// RGB bedroom

int redPin = 3;
int greenPin = 5;
int bluePin = 6;
int aPin = 4;
int bPin = 7;
int buttonPin = 2;

boolean isOn = true;
int color = 0;
// color libary
long colors[48]= {
  0xFF2000, 0xFF4000, 0xFF6000, 0xFF8000, 0xFFA000, 0xFFC000, 0xFFE000, 0xFFFF00, 
  0xE0FF00, 0xC0FF00, 0xA0FF00, 0x80FF00, 0x60FF00, 0x40FF00, 0x20FF00, 0x00FF00,
  0x00FF20, 0x00FF40, 0x00FF60, 0x00FF80, 0x00FFA0, 0x00FFC0, 0x00FFE0, 0x00FFFF,
  0x00E0FF, 0x00C0FF, 0x00A0FF, 0x0080FF, 0x0060FF, 0x0040FF, 0x0020FF, 0x0000FF,
  0x2000FF, 0x4000FF, 0x6000FF, 0x8000FF, 0xA000FF, 0xC000FF, 0xE000FF, 0xFF00FF,
  0xFF00E0, 0xFF00C0, 0xFF00A0, 0xFF0080, 0xFF0060, 0xFF0040, 0xFF0020, 0xFF0000
};

void setup()
{
  pinMode(aPin, INPUT);
  pinMode(bPin, INPUT);
  pinMode(buttonPin, INPUT);
  pinMode(redPin, OUTPUT);
  pinMode(greenPin, OUTPUT);
  pinMode(bluePin, OUTPUT);
}

void loop()
{
  if (digitalRead(buttonPin))
  {
    isOn = ! isOn;
    delay(200);    // de-bounce
  }
  if (isOn)
  {
    int change = getEncoderTurn();
    color = color + change;
    if (color < 0)
    {
      color = 47; 
    }
    else if (color > 47)
    {
      color = 0;
    }
    setColor(colors[color]);
  }
  else
  {
   setColor(0); 
  }
  delay(1);
}

int getEncoderTurn()
{
  // return -1, 0, or +1
  static int oldA = LOW;
  static int oldB = LOW;
  int result = 0;
  int newA = digitalRead(aPin);
  int newB = digitalRead(bPin);
  if (newA != oldA || newB != oldB)
  {
    // something has changed
    if (oldA == LOW && newA == HIGH)
    {
      result = -(oldB * 2 - 1);
    }
  }
  oldA = newA;
  oldB = newB;
  return result;
} 

void setColor(long rgb)
{
  int red = rgb >> 16;
  int green = (rgb >> 8 ) & 0xFF;
  int blue = rgb & 0xFF; 
  analogWrite(redPin, 255 - red);
  analogWrite(greenPin, 255 - green);
  analogWrite(bluePin, 255 - blue);
}

My question is to you ( the forrums users ). Would you help me with this code to make it use 2 encoders for 2 strips and 2 buttons for 2 color swirl on the led strips

Any help appreciated. Thanks.

The AdaEncoder library would help out with the encoders. That appears to be your primary problem?

https://code.google.com/p/adaencoder/wiki/Usage

Thank you for your post.

The problem is that i want to program it so that i can use 2 analoge RGB strips with 2 encoders and 2 butons ( 1 encoder and button for each strip ). The button for color swirl.