Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to read an analog and convert it to real values?
07-02-2013, 07:10 PM,
#1
How to read an analog and convert it to real values?
Hi,
I want to read in RA0 values, and i want to print this values in CDC
is this code ok?

int level;
float b=3.3/1023;
float c=b*level;

void setup(){
TRISCbits.TRISC2 = 0;
LATCbits.LATC2 = LOW;

TRISAbits.TRISA0 = 1;
LATAbits.LATA0 = LOW;

delay(3000);
}

void loop() {

level = analogRead(13); // analog read from RA0
LATCbits.LATC2 = HIGH;

CDC.printf("Level=%f \r\n (Volts)", c);
delay(300);
LATCbits.LATC2 = LOW;
delay(1000);
}

thanks in advance.

regards
Reply
07-02-2013, 09:07 PM,
#2
RE: How to read an analog and convert it to real values?
No. c = b * level; should be in the loop otherwise c has always the same value.

(07-02-2013, 07:10 PM)TuxD3v Wrote: Hi,
I want to read in RA0 values, and i want to print this values in CDC
is this code ok?

int level;
float b=3.3/1023;
float c=b*level;

void setup(){
TRISCbits.TRISC2 = 0;
LATCbits.LATC2 = LOW;

TRISAbits.TRISA0 = 1;
LATAbits.LATA0 = LOW;

delay(3000);
}

void loop() {

level = analogRead(13); // analog read from RA0
LATCbits.LATC2 = HIGH;

CDC.printf("Level=%f \r\n (Volts)", c);
delay(300);
LATCbits.LATC2 = LOW;
delay(1000);
}

thanks in advance.

regards
It is easier to complain than it is to do, but it is better to do than it is to complain.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)