Go Down

Topic: The ² & ³ calculator (Read 4414 times) previous topic - next topic

AJITnayak

i think you havent read post. Parseint function will not work.

So upload my code & continue working
AMPS

Ps991

@AMPS-N But...I have used it before...with the serial monitor. I would type 0-100 in the monitor and Serial.parseInt() would return that number?

Can you explain why it would not work, maybe I am missing something.
If you can't write your program in plain english where anyone could understand it then you have no hope of writing code for it.  -Delta_G

AJITnayak

#17
Jan 06, 2015, 06:50 am Last Edit: Jan 06, 2015, 06:54 am by AMPS-N
I tried ur code .I used simple code from arduino inteself. Where i didn't get integer value.

I am thinking it might be issue with version Of IDE it support.So i have changed code where i am not using parseInt itself.


as per me if my code is working you should proceed with that.

share me latest code ur working using code tag<>. let me check again
AMPS

Ps991

This code works perfectly on 1.0.5, and should be faster and simpler

Code: [Select]
void setup()
{
  Serial.begin(115200);
}

void loop()
{
  if(Serial.available() > 0) //has a number been entered?
  {
    delay(5); //wait for the buffer to fill up
    int test = Serial.parseInt();
    Serial.println(test);
    while(Serial.available() > 0) //parseInt stops when the character is not a number or number is too big, this clears the buffer
      Serial.read();
  }
}


I attached pictures to show some proof  :D
If you can't write your program in plain english where anyone could understand it then you have no hope of writing code for it.  -Delta_G

AJITnayak

#19
Jan 06, 2015, 07:45 am Last Edit: Jan 06, 2015, 07:46 am by AMPS-N
i tried ur code its not working. So if it working on your IDE. i think it better you to sort out the issue.

For above code. the input given & output you expected are really matching???
AMPS

AWOL

Quote
This code works perfectly on 1.0.5, and should be faster and simpler
It doesn't work if you use a terminal emulator instead of the serial monitor.

Hint:
Code: [Select]
delay(5); //wait for the buffer to fill up

Ps991

I tried using MAC OSX terminal by typing "screen <serial_port> <baud_rate>" and again, works perfectly fine. All input values (-32768 to 32767) return exactly as typed.

What do you mean by "doesn't work" and "not working", what does it do?
If you can't write your program in plain english where anyone could understand it then you have no hope of writing code for it.  -Delta_G

AWOL

Code: [Select]
void loop()
{
  if(Serial.available() > 0) //has a number been entered?
  {
    delay(5); //wait for the buffer to fill up
    int test = Serial.parseInt();
    Serial.println(test);
    while(Serial.available() > 0) //parseInt stops when the character is not a number or number is too big, this clears the buffer
      Serial.read();
  }
}

OK, imagine I'm sitting in front of my puTTY window, and I want to find out what the square and cube of "42" is.
I hit the '4' key on my keyboard, and, despite being a reasonably fast typist, I don't manage to hit the '2' key within 5 milliseconds.
In fact, between typing in the '4' and typing in the '2', I decide that I'd like a cup of leaves in boiling water.
You're relying on the timeout of "parseInt" to terminate your number.

Ps991

#23
Jan 06, 2015, 11:55 am Last Edit: Jan 06, 2015, 11:58 am by Ps991
I see somebody is wearing their sarcastic pants today?...I didnt know that putty sends every character you type immediately while the serial monitor only sends when you press enter...

In which case, your code would work...

The 5 milliseconds was for if you typed something like "123sakjdhasdgajhksdgagsjhdfasdf" which would take a little bit of time to load into the buffer before parsing 123 and discarding the rest.

WAIT! Why would you want leaves in boiling water, what type of leaves? Hopefully tea leaves. And you could really decide to have those boiling leaves in a window of 5 milliseconds? I can tell you were'nt being sarcastic here because you said "In fact"... Not gunna lie, Im a little impressed.
If you can't write your program in plain english where anyone could understand it then you have no hope of writing code for it.  -Delta_G

AWOL

Quote
In which case, your code would work..
I haven't posted any of my code, I merely highlighted the contentious section of your code.

Quote
The 5 milliseconds was for if you typed something like "123sakjdhasdgajhksdgagsjhdfasdf"
. . . is the wrong answer.
The 5 milliseconds is to allow the reception of 5 characters at 9600 bits per second (though it's actually more like 5.2ms), assuming the characters are all sent one after the other, which, as I pointed out, is invalid if there's a human (or a very unresponsive machine) at the other end of the serial line.

Ps991

I actually chose the 5 milliseconds randomly, probably because I was using 115200 baud...anywho...I got my answer, OP got his...all is good.

Also I made a mistake saying it was your code, I meant AMPS-N's code on the first page. My bad...
If you can't write your program in plain english where anyone could understand it then you have no hope of writing code for it.  -Delta_G

AWOL

Quote
I actually chose the 5 milliseconds randomly,
Stochastic programming techniques rarely work without some form of feedback mechanism, particularly on microcontrollers, in my experience.

Go Up