/* * Created by ArduinoGetStarted.com * * This example code is in the public domain * * Tutorial page: https://arduinogetstarted.com/tutorials/arduino-potentiometer */ //float floatMap(float x, float in_min, float in_max, float out_min, float out_max) { // return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; //} // the setup routine runs once when you press reset: void setup() { // initialize serial communication at 9600 bits per second: Serial.begin(9600); pinMode(4, INPUT); } // the loop routine runs over and over again forever: void loop() { // read the input on analog pin 4: int analogValue = analogRead(4); // Rescale to potentiometer's voltage (from 0V to 3V): int voltage = map(analogValue, 0, 460, 0, 31); float v2 = voltage/100.0; // print out the value you read: Serial.print("Analog: "); Serial.print(analogValue); Serial.print(", Voltage: "); Serial.println(voltage); delay(1000); }