Multiple independent LED speed control code via multiple potentiometers

Multiple independent LED speed control code via multiple independent potentiometers.

I imagine this to be pretty simple to do.
I only really need to do this with 4 independent outputs and controls.

I was hoping I could do this with 4 analog inputs and 4 digital outputs.

So far I have been using this code for 1 circuit:

int potPin0 = 0;    // select the input pin for the potentiometer
int ledPin0 = 0;
int val = 0;       // variable to store the value coming from the sensor


void setup() {
  pinMode(ledPin0, OUTPUT);  // declare the ledPin as an OUTPUT
 
  
}

void loop() {
  val = analogRead(potPin0);    // read the value from the sensor
  digitalWrite(ledPin0, HIGH);  // turn the ledPin on
  delay(val);                  // stop the program for some time
  digitalWrite(ledPin0, LOW);   // turn the ledPin off
  delay(val);                  // stop the program for some time
                    // stop the program for some time
}

I am still very new to this and need help with the code. I was hoping i could just do this:

int potPin0 = 0;    // select the input pin for the potentiometer
int ledPin0 = 0;
int val = 0;       // variable to store the value coming from the sensor

int potPin1 = 1;
int ledPin1 = 1;

void setup() {
  pinMode(ledPin0, OUTPUT);  // declare the ledPin as an OUTPUT
  pinMode(ledPin1, OUTPUT);  // declare the ledPin as an OUTPUT
  
  
}

void loop() {
  val = analogRead(potPin0);    // read the value from the sensor
  digitalWrite(ledPin0, HIGH);  // turn the ledPin on
  delay(val);                  // stop the program for some time
  digitalWrite(ledPin0, LOW);   // turn the ledPin off
  delay(val);                  // stop the program for some time
  
  
  val = analogRead(potPin0);    // read the value from the sensor
  digitalWrite(ledPin1, HIGH);  // turn the ledPin on
  delay(val)         // stop the program for some time
  digitalWrite(ledPin1, LOW);   // turn the ledPin off
  delay(val)             // stop the program for some time
  
}

But I get problems once I start adding additional "val" commands.

Anyone have any suggestions? Should I go about this differently?
Thanks very much in advance,
-Kevin

"But I get problems once I start adding additional "val" commands."

What kind of problems? You only seem to be reading 1 analog input - did you intend to read 2?

"val" can be 0 to 1023. So once you read, you are not checking anything else for 2 x val, or up to 2 seconds.

Did you want the program to be more responsive? If so, you need to use Blink-without-delay type programming, where you note the time, start the action, and check the time every subsequent pass thru void loop to determine if is time to stop the action.

Sorry, What i meant was:

int potPin0 = 0;    // select the input pin for the potentiometer
int ledPin0 = 0;
int val = 0;       // variable to store the value coming from the sensor

int potPin1 = 1;
int ledPin1 = 1;

void setup() {
  pinMode(ledPin0, OUTPUT);  // declare the ledPin as an OUTPUT
  pinMode(ledPin1, OUTPUT);  // declare the ledPin as an OUTPUT
  
  
}

void loop() {
  val = analogRead(potPin0);    // read the value from the sensor
  digitalWrite(ledPin0, HIGH);  // turn the ledPin on
  delay(val);                  // stop the program for some time
  digitalWrite(ledPin0, LOW);   // turn the ledPin off
  delay(val);                  // stop the program for some time
  
  
  val = analogRead(potPin1);    // read the value from the sensor
  digitalWrite(ledPin1, HIGH);  // turn the ledPin on
  delay(val)         // stop the program for some time
  digitalWrite(ledPin1, LOW);   // turn the ledPin off
  delay(val)             // stop the program for some time
  
}

I was experimenting with the code still..
I would like to have 4 digital outputs turn on and off and have the speed of each controlled by 4 separate analog read/inputs.. via 4 potentiometers.

Is this not possible with this type of code?

If you want a pulse, pause, then a pulse, pause, then a pulse, pause, then a pulse, pause, then restart, sure, that code will work.

If you want pulses that can be independently adjusted, then no. You need to use Blink-without-delay type programming.

Ah ok, thanks. Any suggestions on where to look/search for code that employs that method?

So, if I use this:

/*
  Analog Input
 Demonstrates analog input by reading an analog sensor on analog pin 0 and
 turning on and off a light emitting diode(LED)  connected to digital pin 13. 
 The amount of time the LED will be on and off depends on
 the value obtained by analogRead(). 
 
 The circuit:
 * Potentiometer attached to analog input 0
 * center pin of the potentiometer to the analog pin
 * one side pin (either one) to ground
 * the other side pin to +5V
 * LED anode (long leg) attached to digital output 13
 * LED cathode (short leg) attached to ground
 
 * Note: because most Arduinos have a built-in LED attached 
 to pin 13 on the board, the LED is optional.
 
 
 Created by David Cuartielles
 modified 30 Aug 2011
 By Tom Igoe
 
 This example code is in the public domain.
 
 http://arduino.cc/en/Tutorial/AnalogInput
 
 */

int sensorPin = A0;    // select the input pin for the potentiometer
int ledPin = 13;      // select the pin for the LED
int sensorValue = 0;  // variable to store the value coming from the sensor

void setup() {
  // declare the ledPin as an OUTPUT:
  pinMode(ledPin, OUTPUT);  
}

void loop() {
  // read the value from the sensor:
  sensorValue = analogRead(sensorPin);    
  // turn the ledPin on
  digitalWrite(ledPin, HIGH);  
  // stop the program for <sensorValue> milliseconds:
  delay(sensorValue);          
  // turn the ledPin off:        
  digitalWrite(ledPin, LOW);   
  // stop the program for for <sensorValue> milliseconds:
  delay(sensorValue);                  
}

and alter it, I might be able to have independent multiple speed controls for different pins?

Ok, I have it one potentiometer controlling 4 digital outputs:

/*
  Analog Input
 Demonstrates analog input by reading an analog sensor on analog pin 0 and
 turning on and off a light emitting diode(LED)  connected to digital pin 13. 
 The amount of time the LED will be on and off depends on
 the value obtained by analogRead(). 
 
 The circuit:
 * Potentiometer attached to analog input 0
 * center pin of the potentiometer to the analog pin
 * one side pin (either one) to ground
 * the other side pin to +5V
 * LED anode (long leg) attached to digital output 13
 * LED cathode (short leg) attached to ground
 
 * Note: because most Arduinos have a built-in LED attached 
 to pin 13 on the board, the LED is optional.
 
 
 Created by David Cuartielles
 modified 30 Aug 2011
 By Tom Igoe
 
 This example code is in the public domain.
 
 http://arduino.cc/en/Tutorial/AnalogInput
 
 */

int sensorPin = A0;    // select the input pin for the potentiometer
int ledPin = 0;      // select the pin for the LED
int sensorValue = 0;  // variable to store the value coming from the sensor

int sensorPin1 = A1;
int ledPin1 = 1;

int sensorPin2 = A2;
int ledPin2 = 2;

int sensorPin3 = A3;
int ledPin3 = 3;

void setup() {
  // declare the ledPin as an OUTPUT:
  pinMode(ledPin, OUTPUT);  
  pinMode(ledPin1, OUTPUT);
  pinMode(ledPin2, OUTPUT);
  pinMode(ledPin3, OUTPUT);
  
}

void loop() {
  // read the value from the sensor:
  sensorValue = analogRead(sensorPin); 
  digitalWrite(ledPin, HIGH);  
  digitalWrite(ledPin1, HIGH); 
 digitalWrite(ledPin2, HIGH); 
digitalWrite(ledPin3, HIGH);  
  // stop the program for <sensorValue> milliseconds:
  delay(sensorValue);          
  // turn the ledPin off:        
  digitalWrite(ledPin, LOW); 
digitalWrite(ledPin1, LOW);     
digitalWrite(ledPin2, LOW);   
digitalWrite(ledPin3, LOW);   
  // stop the program for for <sensorValue> milliseconds:
  delay(sensorValue);           


  
}

Any thoughts on how to have each output read from a different analog signal / sensorPin?

nevermind.. I realize now I keep using the delay..
i give up.

Please look at Blink Without Delay in the playground before you give up.

Or this even, maybe more adaptable.

http://arduino.cc/playground/Code/MultiBlink