Hi everyone,
Another question to reveal how little I know about Arduino!
I am trying to write a code to make (at the moment) 3 LEDs fade down or simply turn off as controlled by an LDR, but in an array.
So the code I want would be "The LEDs should always be on UNLESS the LDR value falls below 800, then turn off LED 1 then wait half a second, then turn off LED 2, then wait half a second, then turn off LED 3" etc.
I have the code to make my LEDs turn on and off in an array, and I have the code to fade 3 LEDs out when the LDR values fall, I just can't put them together successfully! I really am terrible at this.
My end goal for this project is to wire up as many LEDs as possible (Arduino cookbook says charlieplexing can run 64 LEDs from one arduino?) and then for them all to go out one by one in reaction to the values on an LDR, or an infrared ranger. Do you guys think that is even possible? I'm not sure if you can control individual LEDs when they are stuffed together in Charlieplexing?
Any suggestions on my immediate coding problem and/or my very big final project problem would be infinitely appreciated.
Thank you,
Jo
P.s. here is the code for fading 3 LEDs which I'm trying to add array information to:
{
//analog in - values from light sensor
//variables
#define ledpinA 2
#define ledpinB 7
#define ledpinC 4
#define sensor 1
int val=0;
int bright=0;
//SETUP
void setup()
{
pinMode(ledpinA,OUTPUT);
pinMode(ledpinB,OUTPUT);
pinMode(ledpinC,OUTPUT);
Serial.begin(9600);
}
//LOOP
void loop()
{
val=analogRead(sensor);
Serial.println(val);
//values up to 917
val=constrain(val,0,917);
bright=map(val,917,0,255,0);
analogWrite(ledpinA,bright);
analogWrite(ledpinB,bright);
analogWrite(ledpinC,bright);
delay(100);
}
}