hello, could someone tell me how to display a percentage at the same time im reading a voltage from a potentiometer?
the pot im reading goes from 0.8 volts to 2.75 volts which ive got displayed on a oled screen,
can anyone tell me how to equate the voltage to a percentage to display on the screen at the same time?
for example if the pot is at 0.80 volts i need the percentage to say 0 % and 2.75 volts to say 100%
any help will be much appreciated as im fairly new to this and stuck
const int LED1 = 9; // the number of the LED 1 pin
const int LED2 = 8; // the number of the LED 2 pin
float potVoltage = 0 ;
int potValue = 0;
#include <arduino.h>
#include <U8g2lib.h>
#include <SPI.h>
#include <Wire.h>
U8G2_SSD1306_128X32_UNIVISION_F_HW_I2C u8g2(U8G2_R0);
float voltageThresholdHigh =2.75;// set the value here to the desired threshold
float voltageThresholdLow = 0.8;// set the value here to the desired threshold
void setup() {
u8g2.begin();
Serial.begin(9600);
}
void loop() {
potValue = analogRead(A0);
u8g2.clearBuffer(); // clear the internal memory
delay(50);
potVoltage = potValue * (5.0 / 1023.0);
// print out the value you read:
u8g2.setFont(u8g2_font_ncenB10_tr); // choose a suitable font
u8g2.setCursor(1,15 );
u8g2.print("Voltage = ");
u8g2. print(potVoltage);
u8g2.sendBuffer();
u8g2.println("[v]");
delay(50);
if (potVoltage>voltageThresholdHigh){
digitalWrite(LED1, HIGH);
digitalWrite(LED2, LOW);
}
if (potVoltage<voltageThresholdLow){
digitalWrite(LED1, LOW);
digitalWrite(LED2, HIGH);
}
if (potVoltage>voltageThresholdLow && potVoltage<voltageThresholdHigh){
digitalWrite(LED1, LOW);
digitalWrite(LED2, LOW);
}
{
}
}