Hi everyone, I have the following code for the sender: (I connected two boards with pins TX, RX)
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
Serial.write(13);
}
And for the receiver:
int receive = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
if(Serial.available())
{
receive = Serial.read();
if(receive == 13)
{
Serial.print("I love arduino");
}
}
}
When I go to the serial port monitor, I can see the words "I love arduino" appear every second. And that's what I want to achieve, except I don't want subtitles to last forever. What do I do to stop broadcasting after sending a message?
Put the print message in the setup() portion of code. The loop can be loop(){}. It will print once then stop. I would add this to the code Serial.print("\n\n\tI love..."); That will give you two blank lines at the start and tab the message in to make it easier to read.
But clearly, you need a power up sequence so that A starts sending 13, B wakes up, sees that and acknowledges, then A stops sending 13.
At least, that's what I make of your somewhat tenuous description of what needs to happen.
C
The 'static' means "This variable is initialized once, and (if changed) keeps its (changed) value even after the function ends." Without it, the variable would be re-created and re-initilized every time that line was executed.