Serial.read into integer - syntax migration probs
hello!
this first code. know little of other languages mel , as2, here, there tricks gotta used to.
the simple code:
the idea send number(id) via serial, , arduino recognize integer , work around number.
by far have this
which prints, if send 8:
0, id: 8
1, id: 8
2, id: 8
3, id: 8
4, id: 8
5, id: 8
6, id: 8
7, id: 8
i can, then, use <id> integer , ok.
but when send number greater 1 digit(12, 145...), messes of course.
in short, i'd know how convert data incoming via serial integer. if send (12, "12", not "1" + "2").
there other issues thought easier solve, syntax won't let me move further. lots of old examples including libraries out of date, , little lost...
thanks in advance!
btp
this first code. know little of other languages mel , as2, here, there tricks gotta used to.
the simple code:
the idea send number(id) via serial, , arduino recognize integer , work around number.
by far have this
code: [select]
int id = 0;
void setup(){
serial.begin(9600);
}
void loop(){
id = serial.read() - '0';
for(int i=0; i<id ; i++){
serial.print(i);
serial.print(", id: ");
serial.println(id,dec);
}
}
which prints, if send 8:
0, id: 8
1, id: 8
2, id: 8
3, id: 8
4, id: 8
5, id: 8
6, id: 8
7, id: 8
i can, then, use <id> integer , ok.
but when send number greater 1 digit(12, 145...), messes of course.
in short, i'd know how convert data incoming via serial integer. if send (12, "12", not "1" + "2").
there other issues thought easier solve, syntax won't let me move further. lots of old examples including libraries out of date, , little lost...
thanks in advance!
btp
first off can't serial read, have wait until there in buffer read. read ascii bytes 1 @ time make number.
something tells stop, non ascii character.
there not out of date regarding syntax. @ :- http://www.arduino.cc/playground/main/interfacingwithsoftware
for examples of how sort of thing. @ processing entry.
something tells stop, non ascii character.
there not out of date regarding syntax. @ :- http://www.arduino.cc/playground/main/interfacingwithsoftware
for examples of how sort of thing. @ processing entry.
Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > Serial.read into integer - syntax migration probs
arduino
Comments
Post a Comment