limiting potentiometer range

can anyone point me in the direction of where i can learn how to limit actions (in this case a blinking led) to a specific range on a potentiometer (i.e. only having the middle of a pot's range effect the blinking rate)

thanks

It is a simple matter of using the "if" construct. Supposed you only want to do something if the value from the pot is in a certian range, then you use:-
val = analogRead(0);
if(val >200 && val < 600) { do stuff here }
This will only do stuff if the value on the pot is between 201 and 599

thanks again!

now I know how to do that, unfortunately I asked the wrong question. basically the problem I'm having is that as my code is below the leds are allowed to chase too fast at the one end of the pot's range and too slow at the other. so I'm assuming I need to change the way the program responds to the values it get's from the pot so that I get a "just right" speed variation
thanks in advance

int potPin = 12;
int val = 0;                   // The higher the number, the slower the timing.
int pins[] = { 2, 3, 4, 5, 6, 7 }; // an array of pin numbers
int num_pins = 6;                  // the number of pins (i.e. the length of the array)

void setup()
{
  int i;

  for (i = 0; i < num_pins; i++)   // the array elements are numbered from 0 to num_pins - 1
    pinMode(pins[i], OUTPUT);      // set each pin as an output
}

void loop()
{  val = analogRead(potPin);
  int i;
  
  for (i = 0; i < num_pins; i++) { // loop through each pin...
    digitalWrite(pins[i], HIGH);   // turning it on,
    delay(val);                  // pausing,
    digitalWrite(pins[i], LOW);    // and turning it off.
    delay(val);
  }
  
}

Look up the map function and compress the range of inputs you are getting so it matches what you want:-
http://www.arduino.cc/en/Reference/Map

1 Like

thanks !

still having a few problems, i'mtrying to limit the pot to a range of 341-681 (so my leds chase just right. I'm trying to learn the map funtion but I'm doing something wrong. any help would be great

int potPin = 2;
int green1Pin = 8;                  // Red LED connected to digital pin 12
int green2Pin = 9;                // Green LED connected to digital pin 11
int yellow1Pin = 10;
int yellow2Pin = 11;
int red1Pin = 12;

int val = analogRead(0);
int  map(val, 0, 1023, 341, 681);

void setup()                      // run once, when the sketch starts
{
  pinMode(green1Pin, OUTPUT);        // sets the digital pin as output
  pinMode(green2Pin, OUTPUT);      
  pinMode(yellow1Pin, OUTPUT);
  pinMode(yellow2Pin, OUTPUT);
  pinMode(red1Pin, OUTPUT);
 
  
}

void loop()                       // run over and over again
{
  val = analogRead(potPin);

  digitalWrite(green1Pin, HIGH);     
  delay(val); 
  val = analogRead(potPin);  
  digitalWrite(green1Pin, LOW);      
  digitalWrite(green2Pin, HIGH);   
  delay(val);   
  val = analogRead(potPin);  
  digitalWrite(green2Pin, LOW);
  digitalWrite(yellow1Pin, HIGH);
  delay(val);
  val = analogRead(potPin);
  digitalWrite(yellow1Pin, LOW);
  digitalWrite(yellow2Pin, HIGH);
  delay(val);
  val = analogRead(potPin);
  digitalWrite(yellow2Pin, LOW);
  digitalWrite(red1Pin, HIGH);
  delay(val);
  val = analogRead(potPin);
  digitalWrite(red1Pin, LOW);
 
  delay(val);

 
  
}

This:

int  map(val, 0, 1023, 341, 681);

is pointless

You need:

void loop()                       // run over and over again
{
  val = analogRead(potPin);
  val = map(val, 0, 1023, 341, 681);  //etc

works like a champ, thanks