Pages: [1]   Go Down
Author Topic: Fload value  (Read 644 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 46
I just want to learn more :)
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

hi all,

i have made:

Code:
lcd.setCursor(0, 1);                       
    int AFCvalue = analogRead(A1);               // Read the AFC input on analog pin 1:
    float AFC = AFCvalue * (4.5 / 1023.0);       // Convert the AFC value (which goes from 0 - 1023) to a voltage (0 - 5V)
   
   if (AFC>2)                                    // A videosignal wil be present higher then 2 volts!
   
{
    digitalWrite(Lockled, HIGH);                 // Turn Lock LED "ON" when Tuner are Locked on frequency
    lcd.setCursor(0,0);
    lcd.print("  L ");
    lcd.print(AFC);
    delay(dt);

   else
{
    digitalWrite(Lockled, LOW);                  // Turn Lock LED "OFF" when Tuner have no signal
    lcd.setCursor(0,0);
    lcd.print("  U ");
    lcd.print(AFC);
    delay(dt);

The output on the LCD "2,38" volt.

My project need a more specific value. example 2,3875 volt. So 4 or maybe 5 digits more are exacter.

what code can i use to make this working?


Edwin
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 604
Posts: 33439
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You need better hardware to get more precession from an A/D converter.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 46
I just want to learn more :)
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You need better hardware to get more precession from an A/D converter.

thx smiley-sad
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17263
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Adafruit carries a couple of nice I2C ADC modules that will give much higher resolution results then the internal ADC does:
https://www.adafruit.com/products/1083
http://www.adafruit.com/products/1085
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 46
I just want to learn more :)
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Adafruit carries a couple of nice I2C ADC modules that will give much higher resolution results then the internal ADC does:
https://www.adafruit.com/products/1083
http://www.adafruit.com/products/1085

ah, this is great.

thanks
Logged

Ontario
Online Online
God Member
*****
Karma: 24
Posts: 863
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


Code:
    lcd.print(AFC);

The output on the LCD "2,38" volt.

My project need a more specific value. example 2,3875 volt. So 4 or maybe 5 digits more are exacter.

If you just want to see more decimal places on your display, do:

Code:
    lcd.print(AFC,4);

Of course, as other have pointed out, the extra decimals really mean nothing since the ADC on the Arduino is not that accurate.  The best you could hope for is about 1 part in 500 accuracy, on a good day, with the wind in the right direction and all that.  And the 3-figure output you've already gotten is more than good enough to represent that.
Logged

Offline Offline
Edison Member
*
Karma: 116
Posts: 2205
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
he output on the LCD "2,38" volt.

You will need to look into lcd.print() and see if / how you can specify more digits.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 46
I just want to learn more :)
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
lcd.print(AFC,4);

this is what I'm looking for.

shame myself, i must know this.

thanks smiley
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


Code:
    lcd.print(AFC,4);

That works great! is there a way to turn off the rounding?
For example I have a float 118.225, I only want to display the first 2 decimal places but lcd.print(COM1A); returns 118.23.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48569
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
is there a way to turn off the rounding?
Write your own function. Not rounding is not a good idea. Why do you want to do that?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
is there a way to turn off the rounding?
Write your own function. Not rounding is not a good idea. Why do you want to do that?

I'm simulating an aviation radio. 118.225 is a communication frequency. The 3rd decimal place is used for tuning calculation but is not displayed to the pilot. So on my LCD I need it to say COM1 = 118.22 , but when I turn my rotary encoder I'm adding .025 to the frequency. So I need to keep the 3 decimal precision but only display the first 2.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48569
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I'm simulating an aviation radio. 118.225 is a communication frequency. The 3rd decimal place is used for tuning calculation but is not displayed to the pilot. So on my LCD I need it to say COM1 = 118.22 , but when I turn my rotary encoder I'm adding .025 to the frequency. So I need to keep the 3 decimal precision but only display the first 2.
Then, you'll need to write your own function.
Logged

Pages: [1]   Go Up
Jump to: