In: Computer Science
Using Arduino
a) write a program that uses two potentiometers to adjust the values displayed on the serial monitor. Have the two values displayed side by side via the serial monitor and each range from 0 to 255
Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. If not, PLEASE let me know before you rate, I’ll help you fix whatever issues. Thanks
//using A0 pin for first analog input
const int analogInPin1 = A0;
//and A1 for second analog input
const int analogInPin2 = A1;
//variables to store values from potentiometers
int p1value = 0;
int p2value = 0;
void setup()
{
Serial.begin(9600);
}
void loop()
{
//reading sensor value from first potentiometer
p1value=analogRead(analogInPin1);
//wrapping signal to a value between 0 and 255
p1value=map(p1value, 0, 1023, 0, 255);
//doing the same for second potentiometer signal
p2value=analogRead(analogInPin2);
p2value=map(p2value, 0, 1023, 0, 255);
//displaying both values in serial output
Serial.print("Potentiometer 1: ");
Serial.print(p1value);
Serial.print(", Potentiometer 2: ");
Serial.println(p2value);
}
/*SCREENSHOT OF CIRCUIT DIAGRAM, CODE AND SERIAL OUTPUT*/