Passing serial data from serial1 to serial2 in an loop endlessly works fine like this;
but when I call this as a function from the loop() like this - It doesn't send or receive
I actually was trying to call the bypass() in a program from a button on a digital input pin that when "on" calls the function and checks to see if the digital pin is still high using the while() but i can't get the basic code to work as a function. I included a debug statement just within the the function and it proves the function is entered but no serial data is sent or received.
Thanks for any help!
Code:
/ the setup function runs once when you press reset or power the board
void setup() {
Serial.begin(9600);
while(!Serial); //wait until serial is opened to run
Serial1.begin(9600);
Serial2.begin(9600);
}
// the loop function runs over and over again forever
void loop()
{
if (Serial1.available()) { // If anything comes in Serial1,
Serial2.write(Serial1.read()); // read it and send it out Serial2
}
if (Serial2.available()) { // If anything comes in Serial2,
Serial1.write(Serial2.read()); // read it and send it out Serial1
}
}
but when I call this as a function from the loop() like this - It doesn't send or receive
Code:
/ the setup function runs once when you press reset or power the board
void setup() {
Serial.begin(9600);
while(!Serial); //wait until serial is opened to run
Serial1.begin(9600);
Serial2.begin(9600);
}
// the loop function runs over and over again forever
void loop()
{
Bypass();
}
static void Bypass()
{
Serial.println("in bypass function");
delay(250);
while(1); {
if (Serial1.available()) { // If anything comes in Serial1,
Serial2.write(Serial1.read()); // read it and send it out Serial2
}
if (Serial2.available()) { // If anything comes in Serial2,
Serial1.write(Serial2.read()); // read it and send it out Serial1
}
}
}
// End of Bypass
I actually was trying to call the bypass() in a program from a button on a digital input pin that when "on" calls the function and checks to see if the digital pin is still high using the while() but i can't get the basic code to work as a function. I included a debug statement just within the the function and it proves the function is entered but no serial data is sent or received.
Thanks for any help!
Last edited: