Programme_arduino_maitre 1.35 KB

#include <SoftwareSerial.h>

SoftwareSerial soft1(10,11);
SoftwareSerial soft2(8,9);

const int in1 = A0;
const int out1 = A1;

int envoi = 0;
String msg="";
int fin1=0;

void setup()
{
  Serial.begin(9600);
  soft1.begin(9600);
  soft2.begin(38400);
  pinMode(in1,INPUT);
  pinMode(out1,OUTPUT);
  digitalWrite(out1,LOW);
}

void loop()
{
  String msg_tmp="";
  String prim = "+\n";
  char inByte = 'a';
  int tps,tps2;
  int timeout=0,timeout2=0;
  int validation = 0;
  if(fin1==0){
  while(envoi==0){
        digitalWrite(out1,HIGH);
        if(digitalRead(in1)==HIGH){
          soft1.print(prim);
          soft1.flush();
          envoi = 1;
          Serial.println("rogt");
        }
  }

    digitalWrite(out1,LOW);
    tps =millis();
  while(timeout <10000){
    timeout = millis() - tps;
    if(digitalRead(in1)==HIGH){
    digitalWrite(out1,HIGH);
    soft1.listen();
    tps2=millis();
    if(soft1.available()>0){
    if(timeout2<50){
    inByte='a';
    while(inByte != '\n'){
      inByte = soft1.read();
      delay(10);
      if(inByte != '\n'){
        msg_tmp += inByte;
        if(inByte == 0x7A){
          msg += msg_tmp;
        }
      }
      }
      Serial.print(msg_tmp);
      }
    }
    }
      msg_tmp="";
      digitalWrite(out1, LOW);
  }
  msg += "\n\n\r";
  Serial.println("blorp");
  Serial.print(msg);
  soft2.print(msg);
  fin1=1;
 }
}