Serial Communication

Hi,

I just began with my course control technology of a microcontroller ( with arduino)
I completed a step of my homework called doing math with serial communication. see the attachment 'doing math'
The next task is to use the serial monitor and type in a value in this case 12 press send and it'll calculate. see the attachment ''uncompleted example'' for what i mean
By using if(serial.available) and serial.parseInt, but i dont have any idea of how to do it.

anyone here can help me out?

thnx

Have you looked up the Serial library and looked at what serial.available does?

Serial.available() will return the number of bytes available to read from the serial port.

To save you some time, try and get one arduino to keep saying "Hello World!" and have the other that is receiving the data keep looping:

//On receiving arduino.

if (Serial.available()>0){
Serial.println(serial.available());
}
//On sending arduino.
delay(500);
Serial.println("Hello World!");

See what you notice and come back to us ;).

the only thing that i notice is that it keeps saying ''hello world''

void setup() {
  Serial.begin(9600);

}
   
  
  
 void loop() {
  if (Serial.available()>0){
Serial.println(Serial.available());
}
   delay(500);
Serial.println("Hello World!");
  }

@Alexlauman,
It must be my day to bitch, so:
If you are in school, college, or whatever, I would expect you could use correct grammar. Sentences start with capital letters, and end with proper punctuations.

thnx is not a word.

Just my minute to bitch I guess!

Alexlauman:
the only thing that i notice is that it keeps saying ''hello world''

Read my post again.

One should have the Serial.available() loop.

The other Arduino the Serial.println("hello world"); loop.

Will not be doing your homework for you, but as an actual teacher...I will give you a small exercise in order for you to understand the principle out of context for you to apply to another...

Hi,

Perhaps, the code on the following pages (especially the first one) can also hopefully shed some light on the use of Serial.available(). I think the example for the Uno is quite simple and is well explained...

Serial - Arduino Reference (there is a link for parseInt() which could be useful to read as well)

dan

Have a look at the examples in Serial Input Basics. One of them is likely to meet your need.

...R