Programming a photocell with if/else and analogWrite
i'm pretty newb @ working arduino (and electronics/circuitry matter) , can't seem figure out how close if/else conditional. i'm trying use photocell light-reactive night light, led turns on when photocell isn't receiving enough light. when first upload code, adequate light, works; led won't turn on. when turn off lamp, light comes on, supposed to. however, once turn lamp on, led doesn't go off. i'm using tri-color led analogwrite rules. can't quite figure out how close make led turn off successfully. in advance help!
code: [select]
void setup() {
serial.begin(9600);
}
void loop() {
int sensorvalue = analogread(a0);
if (sensorvalue < 200) {
for(int b = 0 ; b <= 255; b=b+5)
{
for(int g = 0 ; g <= 255; g=g+5)
{
for(int r= 0 ; r <= 255; r=r+5)
{
analogwrite(9, b);
analogwrite(10, g);
analogwrite(11, r);
delay(10);
}
}
}
}
else {
analogwrite(9, low);
analogwrite(10, low);
analogwrite(11, low);
}
}
this code takes 1,250,000 ms run...
if wait 20 minutes led turn off.
code: [select]
for(int b = 0 ; b <= 255; b=b+5)
{
for(int g = 0 ; g <= 255; g=g+5)
{
for(int r= 0 ; r <= 255; r=r+5)
{
analogwrite(9, b);
analogwrite(10, g);
analogwrite(11, r);
delay(10);
}
}
}
if wait 20 minutes led turn off.
Arduino Forum > Using Arduino > Programming Questions > Programming a photocell with if/else and analogWrite
arduino
Comments
Post a Comment