Go Down

Topic: How to build a string from analogRead values (Read 515 times) previous topic - next topic

invader7

Hello , i want to work with an analog keypad , im getting values with analogRead and my code understands which key is pressed so i can store it at
Code: [Select]
int value = analogRead(1); . Thats ok , now lets say that value has the value 4 , and the next value will be 3 , i want to construct 43 ... i think its not possible with int type , so i have to use String or char , right ?

Thanks

dhenry

You have to decide if you wanted is 43 (a numerical value), or "43", a string of chars.

invader7


You have to decide if you wanted is 43 (a numerical value), or "43", a string of chars.



numeric value is the best for me !

billroy

Think about how this might help:
Code: [Select]

    number = number * 10 + value;


-br

dhenry

A decimal 43 is actually quite difficult to decode later. A hex 43 is far easier to decode and can be constructed easily:

Code: [Select]

value = (value << 4) | (analogRead(1) & 0x0f);


This will retain just the lowest four bits of analogRead().

invader7


Think about how this might help:
Code: [Select]

    number = number * 10 + value;


-br



how simple and great...

dhenry thank you too !

PeterH



You have to decide if you wanted is 43 (a numerical value), or "43", a string of chars.



numeric value is the best for me !


In that case "How to build a string from analogRead values" is a highly misleading title.
I only provide help via the forum - please do not contact me for private consultancy.

Go Up