Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Attach variables

I want to take two variables (in and in2) and put them together, for example:

in = 1;
in2 = 3;

pin = in.in2; // I want this to set pin to 13

The arduino IDE tells me that in is not a class, so what syntax would I use to accomplish this?

EDIT: I figured out a different way to do it, you can just take in. multiply it by 10 and then set pin to the sum of in plus in2

like image 347
Steve Gattuso Avatar asked Feb 12 '26 09:02

Steve Gattuso


1 Answers

If your two variables are definitely integers then

pin = (in*10)+in2;
would work.

If not, read them into strings (maybe with in.toString(), language dependent) and just do

pin = int.parse(in.toString()+in2.toString());
(Although, again dependent on language, you may have to do something other than int.parse [in C# you should use int.TryParse() for example])
like image 121
Ed James Avatar answered Feb 15 '26 10:02

Ed James



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!