Skip to main content
added 23 characters in body
Source Link
Brethlosze
  • 337
  • 1
  • 4
  • 18

How should I index HardwareSerial ports into a single array?.

This compiles, but do not work.

HardwareSerial Serials[]={Serial,Serial1,Serial2,Serial3};

void setup(){
    for (int i=0;i<=3;i++){
        Serials[i].begin(38400);
        while (!Serials[i]);
    }
} 

char s;
void loop(){
    for (int i=0;i<=3;i++){
        if (Serials[i].available()){
            s=Serials[i].read(); 
            Serials[i].write(s); 
        }
    }
}

How should I index HardwareSerial ports into a single array?.

This compiles, but do not work.

HardwareSerial Serials[]={Serial,Serial1,Serial2,Serial3};

setup(){
    for (int i=0;i<=3;i++){
        Serials[i].begin(38400);
        while (!Serials[i]);
    }
}

loop(){
    for (int i=0;i<=3;i++){
        if (Serials[i].available()){
            s=Serials[i].read(); 
            Serials[i].write(s); 
        }
    }
}

How should I index HardwareSerial ports into a single array?.

This compiles, but do not work.

HardwareSerial Serials[]={Serial,Serial1,Serial2,Serial3};

void setup(){
    for (int i=0;i<=3;i++){
        Serials[i].begin(38400);
        while (!Serials[i]);
    }
} 

char s;
void loop(){
    for (int i=0;i<=3;i++){
        if (Serials[i].available()){
            s=Serials[i].read(); 
            Serials[i].write(s); 
        }
    }
}
Source Link
Brethlosze
  • 337
  • 1
  • 4
  • 18

HardwareSerial Indexing Array

How should I index HardwareSerial ports into a single array?.

This compiles, but do not work.

HardwareSerial Serials[]={Serial,Serial1,Serial2,Serial3};

setup(){
    for (int i=0;i<=3;i++){
        Serials[i].begin(38400);
        while (!Serials[i]);
    }
}

loop(){
    for (int i=0;i<=3;i++){
        if (Serials[i].available()){
            s=Serials[i].read(); 
            Serials[i].write(s); 
        }
    }
}