Auto changing the range output variable, from mA to A for example

Hi, I'm making an Inductance meter and I want to automatically convert the output variable, in this case uH to mH, whenever the output surpases the 1E-6 to 1E-3 limit, everything else in the prog is fine, it's an old project from the internet, but in the original they show the same reading at the same time in two different ranges, and I would like to improve that since I have an 0,96" Oled display,wich is super tiny....

Best regards from Cuba and excuse my English...

pcarlos683: Hi, I'm making an Inductance meter and I want to automatically convert the output variable, in this case uH to mH, whenever the output surpases the 1E-6 to 1E-3 limit, everything else in the prog is fine, it's an old project from the internet, but in the original they show the same reading at the same time in two different ranges, and I would like to improve that since I have an 0,96" Oled display,wich is super tiny....

Best regards from Cuba and excuse my English...

Please post the code you currently have/using

Please post the current code but Read this before posting a programming question first

Sorry about that, haven’t read that :slight_smile:

#include<Wire.h>
#include<Adafruit_GFX.h>
#include<Adafruit_SSD1306.h>

double pulse,frequency, inductance;
double capacitance=2.43E-6;

#define ANCHO 128
#define ALTO 64
#define OLED_RESET 4
Adafruit_SSD1306 oled(ANCHO,ALTO,&Wire,OLED_RESET);

void setup() {
pinMode(11,INPUT);//entrada del pulso
pinMode(13,OUTPUT);//salida del pulso
Serial.begin(9600);
Wire.begin();
oled.begin(SSD1306_SWITCHCAPVCC,0x3C);
oled.clearDisplay();
oled.setTextColor(WHITE);
oled.setCursor(4,0);
oled.setTextSize(2);
oled.print(“INDUCTANCE METER”);
oled.display();
oled.setCursor(0,50);
oled.setTextSize(1);
oled.print(“by Ing. Carlos Perez”);
oled.display();
delay(5000);
}

void loop() {
// put your main code here, to run repeatedly:
digitalWrite(13, HIGH);
delay(100);
digitalWrite(13, LOW);
delayMicroseconds(100);
pulse= pulseIn(11,HIGH,5000);

if(pulse>0.1)
{
frequency=1.E6/(2pulse);
inductance=1./(capacitance
frequencyfrequency4.3.141593.14159);
inductance *=1E6;
}

//Serial.println(frequency);

oled.clearDisplay();
oled.setTextColor(WHITE);
oled.setCursor(0,30);
oled.setTextSize(5);
oled.print(pulse);
oled.display();
//delay(1000);

}

the original prog calculates this

inductance *=1E6;
inductance_mH = inductance *1000;

then they print the two at the same time

oled.print(inductance);
oled.print(inductance_mH);

What can I improve here??

Sorry about that, haven't read that

It is no good reading it if you don't follow the advice it gives

If you have read it now did you decide to ignore the advice given ?

I’m a bit confused, but could you tell me what’s the mistake, I explained the purpose of the project, and the code, and I describe what I EXPECT to happen, I do not have much experience in Forums but I would like to fit in

pcarlos683: inductance *=1E6; inductance_mH = inductance *1000;

you sure that is how its calculated?

if

'inductance *=1E6;' give you the value in uH then surely to get the value in mH you would then do 'inductance/1000' NOT 'inductance *1000'.

anyway, to answer your question:

pcarlos683: What can I improve here??

a simple if statement should do the trick to allow autoranging. somthing like this in your code maybe (below btw is the format the forum expects codes to be posted! ;) ):

inductance *=1E6; //convert inductance to uH
if(inductance >=1000) inductance /=1000 ; //convert inductance to mH

oled.print(inductance);

hope that helps...

but could you tell me what's the mistake,

What was the advice given about how to post code ?

yep, it'll do the trick...sorry about the code, its a mess around here, I have like 3 pages open at the same time, I think once in an IF condition but wasn't sure that works, Im an Electric Engineer but my capabilities in C+ are limited to Matlab, this whole thing with Arduino makes my mind blow with old projects...

THANK YOU VERY MUCH