Hi I had a problem with reading int - kept reading them as decimals!
So I figured I would read the numbers as chars and then convert them with atoi!
I told me a had to us
char * g;
instead of:
char g;
in order to use atoi();
but the following didnt work:
char * char1;
char1 = Serial.read();
WHAT SHOULD I DO
Any help will be appriciated
WHAT SHOULD I DO
RTFM, instead of posting questions every five minutes.
there isnt one
cant find anything usefull to me for this scenario
please tell me the answer instead of general links
char * char1;
char1 = Serial.read();
This didn't work because you can't assign an int to a char pointer.
so how can I read a value and assign it to a char *?
You can't assign a value to a char pointer like that.
You assign the value to what the pointer points to, but first you need to make sure the pointer points to something.
Try something like this:
void loop() {
int c;
static int the_number = 0;
if (Serial.available() > 0) {
c = Serial.read();
if (c >= '0' && c <= '9') {
the_number = 10 * the_number + c - '0';
} else {
Serial.print("the number is ");
Serial.println(the_number);
the_number = 0;
}
}
}