starting over the void loop when i adjust the pot

so i made this really simple LED blinking pattern that the speed of the blinking is adjusted by a potentiometer. the only problem is that for an adjustment to take place, i have to adjust the pot then wait for the void loop to start over before i can tell how much faster/slower the adjustment made it.

how do i make it so that whenever i move the pot, the void loop starts over?

ignore my noobyness, i had to leave some of the notes in there on how to wire a pot :P

code :

/* 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

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()
{
  
  sensorValue = analogRead(sensorPin);    
  
  
  
  digitalWrite(LED, HIGH);
  delay(sensorValue);
  digitalWrite(LED, LOW);

  digitalWrite(LED1, HIGH);
  delay(sensorValue);
  digitalWrite(LED1, LOW);
  
  digitalWrite(LED2, HIGH);
  delay(sensorValue);
  digitalWrite(LED2, LOW);
  
  digitalWrite(LED3, HIGH);
  delay(sensorValue);
  digitalWrite(LED3, LOW);

  digitalWrite(LED4, HIGH);
  delay(sensorValue);
  digitalWrite(LED4, LOW);

  digitalWrite(LED5, HIGH);
  delay(sensorValue);
  digitalWrite(LED5, LOW);
  
  digitalWrite(LED6, HIGH);
  delay(sensorValue);
  digitalWrite(LED6, LOW);
  
  digitalWrite(LED7, HIGH);
  delay(sensorValue);
  digitalWrite(LED7, LOW);
  
  digitalWrite(LED6, HIGH);
  delay(sensorValue);
  digitalWrite(LED6, LOW);
  
  digitalWrite(LED5, HIGH);
  delay(sensorValue);
  digitalWrite(LED5, LOW);
  
  digitalWrite(LED4, HIGH);
  delay(sensorValue);
  digitalWrite(LED4, LOW);
  
  digitalWrite(LED3, HIGH);
  delay(sensorValue);
  digitalWrite(LED3, LOW);

  digitalWrite(LED2, HIGH);
  delay(sensorValue);
  digitalWrite(LED2, LOW);
  
  digitalWrite(LED1, HIGH);
  delay(sensorValue);
  digitalWrite(LED1, LOW);
  
  
  
}

If you read the sensorValue before every delay(sensorValue); the pot will have an immediate effect. It won't restart the loop though if that is important.

You could have nothing happening until you moved the pot. That could be done with a wile(something = something){} //while .... do nothing

Mowcius

Another thing you could do is look at the BlinkWithoutDelay example. You would need to keep track of when it was time to change an LED state, and determine if it was time to do something.

This would make loop be called much more frequently, making the reading of the pot pin happen much more often, significantly shortening the time between a pot change and an effect.

Jabber, how would i go about doing that?

how would i go about doing that?

Like this:

void loop()
{
  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);

  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);
}

perfect! fixed my problem!

thanks!