Problem with writing code for Light project.
dear forum members.
my name bas de boer. love using arduino , making projects it. time have little problem the code.
i'm making analog rgb strips light bedroom. , want use 2 rotary encoders , 2 switches 2 rgb strips. 1 encoder , switch 1 strip
the project this;
with encoders wan't select colors of rgb led strips. 1 encoder , 1 switch ( make color swirl ) vor each strip.
i have problems making code. have a piece of code works with one encoder , no color swirl.
( code 1 rotary encoder );
my question ( forrums users ). me code make use 2 encoders for 2 strips , 2 buttons 2 color swirl on led strips
any appreciated. thanks.
my name bas de boer. love using arduino , making projects it. time have little problem the code.
i'm making analog rgb strips light bedroom. , want use 2 rotary encoders , 2 switches 2 rgb strips. 1 encoder , switch 1 strip
the project this;
with encoders wan't select colors of rgb led strips. 1 encoder , 1 switch ( make color swirl ) vor each strip.
i have problems making code. have a piece of code works with one encoder , no color swirl.
( code 1 rotary encoder );
code: [select]
// 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)
{
// 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 ( forrums users ). me code make use 2 encoders for 2 strips , 2 buttons 2 color swirl on led strips
any appreciated. thanks.
the adaencoder library out encoders. appears primary problem?
https://code.google.com/p/adaencoder/wiki/usage
https://code.google.com/p/adaencoder/wiki/usage
Arduino Forum > Using Arduino > Project Guidance > Problem with writing code for Light project.
arduino
Comments
Post a Comment