two consecutive chars to one int.
quick question:
is there easy way read 2 consecutive chars or bytes from serial buffer , combine them 1 integer?
for example, char 1 , char 2 read until '/' read combined make 12.
i'd avoid using string if possible.
thanks!
is there easy way read 2 consecutive chars or bytes from serial buffer , combine them 1 integer?
for example, char 1 , char 2 read until '/' read combined make 12.
i'd avoid using string if possible.
thanks!
if understand problem, might lead answer:
code: [select]
void setup() {
int answer;
char mychar[3];
serial.begin(9600);
mychar[0] = '1'; // use serial.read() these , keyboard or wherever...
mychar[1] = '2';
mychar[2] = '/';
if (mychar[2] == '/')
mychar[2] = '\0'; // make c string
answer = atoi(mychar);
serial.println(answer);
}
void loop() {
}
Arduino Forum > Using Arduino > Programming Questions > two consecutive chars to one int.
arduino
Comments
Post a Comment