Hello all, got started playing with the arduino and uhh. Looked on the forums and havent seen really anything on this which it seems pretty simple i'm just a noob i guess and i know my code isn't very efficent. Let me know of much needed improvements.
Setup: I have 6 LED's all needing the ability to be dimmed seperately so im using the PWM channels. I'm also using an IR sensor as a switch. Right now I have it setup as once the switch/IR sensor is triggered, the first led in the string turns on dimming from off to on Then the second, and so forth. Works great but not really what im looking for. I'm looking for when the first LED is triggered it goes half way brightness (1-127 on a 1-255 analog scale), then from there the second LED does the same as the first LED but the first LED goes to full brightness while the second one has started its cycle. Then it keeps going till the last one. Let me know what you guys come up with. My Code as of now is below. Pardon my ignorance. ;D
int led13 = 11; // LED connected to digital pin 11
int led12 = 10;
int led11 = 9;
int led10 = 6;
int led09 = 5;
int led08 = 3;
void setup() // run once, when the sketch starts
{
pinMode(led13, OUTPUT); // sets the digital pin as output
pinMode(led12, OUTPUT);
pinMode(led11, OUTPUT);
pinMode(led10, OUTPUT);
pinMode(led09, OUTPUT);
pinMode(led08, OUTPUT);
}
void loop() // run over and over again
{
int analogValue = analogRead(0);
int analogValue1 = analogRead(2);
Serial.println(analogValue);
Serial.println(analogValue1);
delay(10);
if (analogValue > 500) {
for(int fadeValue = 0; fadeValue <= 255; fadeValue += 5){
analogWrite(led13, fadeValue);
delay(30);
}
for(int fadeValue = 0; fadeValue <= 255; fadeValue += 5){
analogWrite(led12, fadeValue);
delay(30);
}