I am trying to map potentiometers serial values from 0-1023 to 0-255 however it seems to be broken as it reads 0-675 both before I added the map function and after. I have also tried changing 1023 to 675 and still doesn't work.
I know this will be and easy fix but got no idea what I've done wrong here.
// Code for Potentiometers
byte Pots[] = {A0, A1, A2, A3, A4}; //define analog inputs connected to pots
byte numberPots = 5; //number of inputs to read
void setup() {
Serial.begin(9600);
for (byte i = 0; i < numberPots; i++){
map (Pots[i], 0, 1023, 0, 255);
}
}
void loop() {
for (byte i = 0; i < numberPots; i++) {
Serial.print(analogRead(Pots[i])); //print value read from pot
Serial.print(" "); //space between sensor value and text
}
Serial.println(); //print blank line between groups of output
delay(1000); //slows loop to once per second
}
map() works on the value of the analogRead() function. It does not change the range of the values returned from an analogRead().
// Code for Potentiometers
byte Pots[] = {A0, A1, A2, A3, A4}; //define analog inputs connected to pots
byte numberPots = 5; //number of inputs to read
void setup() {
Serial.begin(9600);
for (byte i = 0; i < numberPots; i++){
map (Pots[i], 0, 1023, 0, 255);
}
}
void loop() {
for (byte i = 0; i < numberPots; i++) {
int val = map(analogRead(Pots[i]), 0, 1023, 0, 255 );
Serial.print(val); //print value read from pot
Serial.print(" "); //space between sensor value and text
}
Serial.println(); //print blank line between groups of output
delay(1000); //slows loop to once per second
}
blh64:
map() works on the value of the analogRead() function. It does not change the range of the values returned from an analogRead().
// Code for Potentiometers
byte Pots[] = {A0, A1, A2, A3, A4}; //define analog inputs connected to pots
byte numberPots = 5; //number of inputs to read
void setup() {
Serial.begin(9600);
for (byte i = 0; i < numberPots; i++){
map (Pots[i], 0, 1023, 0, 255);
}
}
void loop() {
for (byte i = 0; i < numberPots; i++) {
int val = map(analogRead(Pots[i]), 0, 1023, 0, 255 );
Serial.print(val); //print value read from pot
Serial.print(" "); //space between sensor value and text
}
Serial.println(); //print blank line between groups of output
delay(1000); //slows loop to once per second
}
// Code for Potentiometers
const byte NumberPots = 5; //number of inputs to read
const byte PotPins[NumberPots] = {A0, A1, A2, A3, A4}; //define analog inputs connected to pots
void setup()
{
Serial.begin(115200);
}
void loop()
{
for (byte i = 0; i < NumberPots; i++)
{
int val = map(analogRead(PotPins[i]), 0, 1023, 0, 255);
Serial.print(val); //print value read from pot
Serial.print(" "); //space between sensor value and text
}
Serial.println(); //print blank line between groups of output
delay(1000); //slows loop to once per second
}