Analog input chang in int
Topic last updated
21 Nov 2012, by
Daniel Moser.
7 replies
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
Replies
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;
}
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
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.
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.
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.
Thanks for the help it's very helpfull
alim_sheikh
#
21 Nov 2012
Is it possible to read images from PC and do some processing on it and show the result on MBED.
Please log in to post a reply.
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