Analog input chang in int

12 Oct 2012

How is it poosible to read in an analog Input an that this Inout to convert to an int. Sorry my english isnt the best I mean if

int dout;

aint = 0 -> dout= 0

aint = 0.1 -> dout= 6

aint = 0.2 -> dout= 12

aint = 1 -> dout= 60

Thanks for the help

12 Oct 2012

If you want you can use read_u16 to get it directly as integer (see: http://mbed.org/handbook/AnalogIn), but in this case it is simply multiplying it by 60. So:

AnalogIn aint(p20);

int main() {
  int dout = aint * 60;
}
22 Oct 2012

thanks that run but if dout should be under 10 it looks like 90 and not 9 or 80 and not 8. How can i clear the 0 behind the 9 or can i make the 90 too a 09.

And is this too possible with letters from a-z

Tanks for reply

23 Oct 2012

Why would you want to map letters on analog input?

If dout should be under 10 you obviously shouldnt multiply it by 60. AnalogIn returns a result between 0 and 1. So if you want the output to be between 0 and 10, you need to multiply it by 10.

24 Oct 2012

I would like to write somthing on a lCD-Panel. An otherquestion is it possible to invert the analog input signal? Thanks for the replys.

24 Oct 2012

dout = (1-aint)*10;

You can just use simple math for such stuff.

And if you want to map letters on analog input, you mean a is the lowest, z the highest? What you can do is:

AnalogIn aint(p20);
 
int main() {
  int dout = aint * 26;  //26 steps obviously
  char charout = dout + 'a';
}

If you look at an ascii table you see that the letters are just in alphabetical order. If you write in code 'a' it will take the ascii value of a. Then you add dout value and you get the letter you want.

25 Oct 2012

Thanks for the help it's very helpfull

21 Nov 2012

Is it possible to read images from PC and do some processing on it and show the result on MBED.