i really hope im not overstaying my welcome by asking so many questions, but ive been trying to work this out for about 40 minutes and keep getting worse and worse results.
basically what im doing is i have an LED pattern going, (LED, LED1, LED2, all the way to LED7), and then i have another LED (LED8) that is fading in and out. at the same time. Now i also have a pot that is controlling the speed of the pattern of LEDs, but i also want this same pot to control the speed of the fade of the LED. i want it so that after the void loop has completed once, it is as bright as its going to be, then as its competed again its completely faded off.
i tried to combine a code in the examples for a fading LED but it is not fading at all, and making LED6 and LED not blink in the pattern (it pauses right before it gets to those LEDs)
take a look at my code and see what you guys think..
/* this is a blinking pattern with a potentiometer to control speed. connect the pots first pin (left) to Gnd
second pin to a resistor then to analog pin 1, then the last pit to the 5V
*/
#define LED 13
#define LED1 12
#define LED2 11
#define LED3 10
#define LED4 9
#define LED5 8
#define LED6 7
#define LED7 6
#define LED8 5
int sensorPin = 0; // select the input pin for the potentiometer
int sensorValue = 0; // variable to store the value coming from the sensor
void setup()
{
pinMode(LED, OUTPUT);
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(LED3, OUTPUT);
pinMode(LED4, OUTPUT);
pinMode(LED5, OUTPUT);
pinMode(LED6, OUTPUT);
pinMode(LED7, OUTPUT);
}
void loop(){
for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=5) {
// sets the value (range from 0 to 255):
analogWrite(LED8, fadeValue);
delay(sensorValue);
digitalWrite(LED, HIGH);
sensorValue = analogRead(sensorPin);
delay(sensorValue);
digitalWrite(LED, LOW);
digitalWrite(LED1, HIGH);
sensorValue = analogRead(sensorPin);
delay(sensorValue);
digitalWrite(LED1, LOW);
digitalWrite(LED2, HIGH);
sensorValue = analogRead(sensorPin);
delay(sensorValue);
digitalWrite(LED2, LOW);
digitalWrite(LED3, HIGH);
sensorValue = analogRead(sensorPin);
delay(sensorValue);
digitalWrite(LED3, LOW);
digitalWrite(LED4, HIGH);
sensorValue = analogRead(sensorPin);
delay(sensorValue);
digitalWrite(LED4, LOW);
digitalWrite(LED5, HIGH);
sensorValue = analogRead(sensorPin);
delay(sensorValue);
digitalWrite(LED5, LOW);
digitalWrite(LED6, HIGH);
sensorValue = analogRead(sensorPin);
delay(sensorValue);
digitalWrite(LED6, LOW);
for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=5)
// sets the value (range from 0 to 255):
analogWrite(LED8, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(sensorValue);
digitalWrite(LED7, HIGH);
sensorValue = analogRead(sensorPin);
delay(sensorValue);
digitalWrite(LED7, LOW);
digitalWrite(LED6, HIGH);
sensorValue = analogRead(sensorPin);
delay(sensorValue);
digitalWrite(LED6, LOW);
digitalWrite(LED5, HIGH);
sensorValue = analogRead(sensorPin);
delay(sensorValue);
digitalWrite(LED5, LOW);
digitalWrite(LED4, HIGH);
sensorValue = analogRead(sensorPin);
delay(sensorValue);
digitalWrite(LED4, LOW);
digitalWrite(LED3, HIGH);
sensorValue = analogRead(sensorPin);
delay(sensorValue);
digitalWrite(LED3, LOW);
digitalWrite(LED2, HIGH);
sensorValue = analogRead(sensorPin);
delay(sensorValue);
digitalWrite(LED2, LOW);
digitalWrite(LED1, HIGH);
sensorValue = analogRead(sensorPin);
delay(sensorValue);
digitalWrite(LED1, LOW);
}
}