Have a look at the examples in Serial Input Basics - simple reliable ways to receive data. There is also a parse example to illustrate how to extract numbers from the received text.
Jatin1o1:
I tried working in loop too. i added if (serial.availabe>0) {......}
but it didnt worked out too
You need to post the latest version of your program so we can see exactly what you tried.
Also "didn't work" provides no useful information from which to help you. Please give as much detail as you can about what happens when you run the program.
Robin2:
You need to post the latest version of your program so we can see exactly what you tried.
Also "didn't work" provides no useful information from which to help you. Please give as much detail as you can about what happens when you run the program.
...R
Code 1 and code 2 both are latest version of the codes.
you can please Trying running it on your arduino while attaching a servo on pin 9
Jatin1o1:
Code 1 and code 2 both are latest version of the codes.
I find that hard to believe considering what you said in Reply #4 which was written after you posted the code in your Original Post. And if you have another version please put it in your next Post so we can compare it with the version in the Original Post.
you can please Trying running it on your arduino while attaching a servo on pin 9
If the version of "Code 2" in the first post is really your latest version then you have completely ignored all advice given to you.
loop() is still empty. So serialEvent() is never called. So it's hardly surprising that the program doesn't use any values from the serial monitor. And sweep() is never called in loop() so obviously the servo is never going to move.
slipstick:
If the version of "Code 2" in the first post is really your latest version then you have completely ignored all advice given to you.
loop() is still empty. So serialEvent() is never called. So it's hardly surprising that the program doesn't use any values from the serial monitor. And sweep() is never called in loop() so obviously the servo is never going to move.
Steve
Pardon me for not getting with latest post.
I got quite busy because of my semester examinations.
I think that would be interpreted first time around as
for (0 - 0; 0/1000 < 0; cm = millis()) {
and next time round it might be (if millis() happened to be 750)
for (750 - 0; 750/1000 < 0; cm = millis()) {
However I cannot see any situation in which cm/1000 could be a negative number so the test cm/1000 < 0 will always fail.
Of course I might misunderstand.
My suggestion is to make a much simpler FOR loop. Or maybe change it to a WHILE loop and do the time checking within the WHILE. But that brings me right around to using a simple IF and allowing loop() to do the iteration - for example
if (millis() - prevTime >= desiredInterval) {
prevTime = millis();
// do whatever needs to be done
}
Robin2:
I have never seen a FOR loop like this before
for (cm-pm;cm/1000 < jatink;cm=millis()){
I think that would be interpreted first time around as
for (0 - 0; 0/1000 < 0; cm = millis()) {
and next time round it might be (if millis() happened to be 750)
for (750 - 0; 750/1000 < 0; cm = millis()) {
However I cannot see any situation in which cm/1000 could be a negative number so the test cm/1000 < 0 will always fail.
Of course I might misunderstand.
My suggestion is to make a much simpler FOR loop. Or maybe change it to a WHILE loop and do the time checking within the WHILE. But that brings me right around to using a simple IF and allowing loop() to do the iteration - for example
if (millis() - prevTime >= desiredInterval) {
prevTime = millis();
// do whatever needs to be done
}
which is how things are done in the demo [Several Things at a Time](http://forum.arduino.cc/index.php?topic=223286.0)
...R