Hello Team!
I hope everyone is doing well! I have a question about my program. I have set up a simple program to test a bunch of LED's and Potentiometers that I just purchased. I'd like to make an enhancement to the program:
int potPin = A0; // Potentiometer Pin
int led1 = 13; // Green
int led2 = 11; // Green
int led3 = 9; // Green
int led4 = 7; // Yellow
int led5 = 5; // Yellow
int led6 = 3; // Red
int potValue = 0; // variable from the sensor
void setup() {
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
pinMode(led5, OUTPUT);
pinMode(led6, OUTPUT);
Serial.begin(9600);
}
void loop(){
potValue = analogRead(potPin);
digitalWrite(led1, HIGH);
Serial.println(potValue);
delay(potValue/4);
potValue = analogRead(potPin);
digitalWrite(led2, HIGH);
Serial.println(potValue);
delay(potValue/4);
potValue = analogRead(potPin);
digitalWrite(led3, HIGH);
Serial.println(potValue);
delay(potValue/4);
potValue = analogRead(potPin);
digitalWrite(led4, HIGH);
Serial.println(potValue);
delay(potValue/4);
potValue = analogRead(potPin);
digitalWrite(led5, HIGH);
Serial.println(potValue);
delay(potValue/4);
potValue = analogRead(potPin);
digitalWrite(led6, HIGH);
Serial.println(potValue);
delay(potValue/4);
digitalWrite(led1, LOW);
Serial.println(potValue);
delay(potValue/4);
potValue = analogRead(potPin);
digitalWrite(led2, LOW);
Serial.println(potValue);
delay(potValue/4);
potValue = analogRead(potPin);
digitalWrite(led3, LOW);
Serial.println(potValue);
delay(potValue/4);
potValue = analogRead(potPin);
digitalWrite(led4, LOW);
Serial.println(potValue);
delay(potValue/4);
potValue = analogRead(potPin);
digitalWrite(led5, LOW);
Serial.println(potValue);
delay(potValue/4);
potValue = analogRead(potPin);
digitalWrite(led6, LOW);
Serial.println(potValue);
delay(potValue/4);
}
Because the analogRead has a range from 0-1023, and because that value is used to determine the speed of the LED chase, I would like to map the values to make the speed transitions more visibly consistent (I think a few of my potentiometers are bad), but I'm not sure on how to use the function correctly. Do I need to repeat the map() function in each step, or is it possible to implement it in the void setup() function so that it repeats itself automatically... I've read the documentation ( http://www.arduino.cc/en/Reference/Map ) on mapping but I'm still unsure of what to do.
Thank You Team!
MonorailOrange