Commit d4a6dccad49eae709fef930c66daecbd4f45ea6b

Authored by sblas
1 parent 8b38af38

Ajout du programme pour arduino maitre

Showing 1 changed file with 77 additions and 0 deletions   Show diff stats
Programme_arduino_maitre 0 → 100644
@@ -0,0 +1,77 @@ @@ -0,0 +1,77 @@
  1 +
  2 +#include <SoftwareSerial.h>
  3 +
  4 +SoftwareSerial soft1(10,11);
  5 +SoftwareSerial soft2(8,9);
  6 +
  7 +const int in1 = A0;
  8 +const int out1 = A1;
  9 +
  10 +int envoi = 0;
  11 +String msg="";
  12 +int fin1=0;
  13 +
  14 +void setup()
  15 +{
  16 + Serial.begin(9600);
  17 + soft1.begin(9600);
  18 + soft2.begin(38400);
  19 + pinMode(in1,INPUT);
  20 + pinMode(out1,OUTPUT);
  21 + digitalWrite(out1,LOW);
  22 +}
  23 +
  24 +void loop()
  25 +{
  26 + String msg_tmp="";
  27 + String prim = "+\n";
  28 + char inByte = 'a';
  29 + int tps,tps2;
  30 + int timeout=0,timeout2=0;
  31 + int validation = 0;
  32 + if(fin1==0){
  33 + while(envoi==0){
  34 + digitalWrite(out1,HIGH);
  35 + if(digitalRead(in1)==HIGH){
  36 + soft1.print(prim);
  37 + soft1.flush();
  38 + envoi = 1;
  39 + Serial.println("rogt");
  40 + }
  41 + }
  42 +
  43 + digitalWrite(out1,LOW);
  44 + tps =millis();
  45 + while(timeout <10000){
  46 + timeout = millis() - tps;
  47 + if(digitalRead(in1)==HIGH){
  48 + digitalWrite(out1,HIGH);
  49 + soft1.listen();
  50 + tps2=millis();
  51 + if(soft1.available()>0){
  52 + if(timeout2<50){
  53 + inByte='a';
  54 + while(inByte != '\n'){
  55 + inByte = soft1.read();
  56 + delay(10);
  57 + if(inByte != '\n'){
  58 + msg_tmp += inByte;
  59 + if(inByte == 0x7A){
  60 + msg += msg_tmp;
  61 + }
  62 + }
  63 + }
  64 + Serial.print(msg_tmp);
  65 + }
  66 + }
  67 + }
  68 + msg_tmp="";
  69 + digitalWrite(out1, LOW);
  70 + }
  71 + msg += "\n\n\r";
  72 + Serial.println("blorp");
  73 + Serial.print(msg);
  74 + soft2.print(msg);
  75 + fin1=1;
  76 + }
  77 +}