Commit 8b38af38de19c091733e74dfe3711a3a9b2d2920

Authored by sblas
0 parents

Ajout du programme pour brique esclave

Showing 1 changed file with 246 additions and 0 deletions   Show diff stats
Programme_arduino_esclave 0 → 100644
  1 +++ a/Programme_arduino_esclave
... ... @@ -0,0 +1,246 @@
  1 +#include <SoftwareSerial.h>
  2 +
  3 +SoftwareSerial soft1(A3,A2);
  4 +SoftwareSerial soft2(6,5);
  5 +SoftwareSerial soft3(9,10);
  6 +
  7 +const int in1 = A5;
  8 +const int out1 = A4;
  9 +
  10 +const int in2 = 8;
  11 +const int out2 = 7;
  12 +
  13 +const int in3 = 11;
  14 +const int out3 = 12;
  15 +
  16 +const int in4 = 2;
  17 +const int out4 = 3;
  18 +
  19 +int prem = 0;
  20 +int papa = 0;
  21 +
  22 +int potar = A0;
  23 +
  24 +void setup()
  25 +{
  26 + Serial.begin(9600);
  27 + soft1.begin(9600);
  28 + soft2.begin(9600);
  29 + soft3.begin(9600);
  30 +
  31 + pinMode(in1,INPUT);
  32 + pinMode(out1,OUTPUT);
  33 + pinMode(in2,INPUT);
  34 + pinMode(out2,OUTPUT);
  35 + pinMode(in3,INPUT);
  36 + pinMode(out3,OUTPUT);
  37 + pinMode(in4,INPUT);
  38 + pinMode(out4,OUTPUT);
  39 +
  40 + digitalWrite(out1,LOW);
  41 + digitalWrite(out2,LOW);
  42 + digitalWrite(out3,LOW);
  43 + digitalWrite(out4,LOW);
  44 +}
  45 +
  46 +void loop()
  47 +{
  48 + String msg="";
  49 + char inByte='a';
  50 + int tps;
  51 + int timeout;
  52 + int fin1=0,fin2=0,fin3=0,fin4=0;
  53 + char id = 0b01100001;
  54 + if(digitalRead(in1)==HIGH){
  55 + digitalWrite(out1,HIGH);
  56 + soft1.listen();
  57 + timeout=0;
  58 + tps=millis();
  59 + while(soft1.available()<=0 && timeout<1000){
  60 + timeout= millis() - tps;
  61 + }
  62 + if(timeout<1000){
  63 + fin1=1;
  64 + while(inByte != '\n'){
  65 + inByte = soft1.read();
  66 + if(inByte !='\n'){
  67 + msg += inByte;
  68 + delay(10);
  69 + }
  70 + }
  71 + if(prem==0){
  72 + prem=1;
  73 + papa=1;
  74 + msg += id;
  75 + if((id & 0xF0) ==0x60) msg += '{'; //char pour 123
  76 + else if((id & 0xF0) ==0x40) msg += 0b00000100;
  77 + msg += '\n';
  78 + }
  79 + else msg+= '\n';
  80 + }
  81 + digitalWrite(out1, LOW);
  82 + delay(50);
  83 + }
  84 +
  85 + else if(digitalRead(in2)==HIGH){
  86 + digitalWrite(out2,HIGH);
  87 + soft2.listen();
  88 + timeout=0;
  89 + tps=millis();
  90 + while(soft2.available()<=0 && timeout<1000){
  91 + timeout= millis() - tps;
  92 + }
  93 + if(timeout<1000){
  94 + fin2=1;
  95 + while(inByte != '\n'){
  96 + inByte = soft2.read();
  97 + if(inByte !='\n'){
  98 + msg += inByte;
  99 + delay(10);
  100 + }
  101 + }
  102 + if(prem==0){
  103 + prem=1;
  104 + papa=2;
  105 + msg += id;
  106 + if((id & 0xF0) ==0x60) msg += '{'; //char pour 123
  107 + else if((id & 0xF0) ==0x40) msg += 0b00000100;
  108 + msg += '\n';
  109 + }
  110 + else msg+= '\n';
  111 + }
  112 + digitalWrite(out2, LOW);
  113 + delay(50);
  114 + }
  115 +
  116 +else if(digitalRead(in3)==HIGH){
  117 + digitalWrite(out3,HIGH);
  118 + soft3.listen();
  119 + timeout=0;
  120 + tps=millis();
  121 + while(soft3.available()<=0 && timeout<1000){
  122 + timeout= millis() - tps;
  123 + }
  124 + if(timeout<1000){
  125 + fin3=1;
  126 + while(inByte != '\n'){
  127 + inByte = soft3.read();
  128 + if(inByte !='\n'){
  129 + msg += inByte;
  130 + delay(10);
  131 + }
  132 + }
  133 + if(prem==0){
  134 + prem=1;
  135 + papa=3;
  136 + msg += id;
  137 + if((id & 0xF0) ==0x60) msg += '{'; //char pour 123
  138 + else if((id & 0xF0) ==0x40) msg += 0b00000100;
  139 + msg += '\n';
  140 + }
  141 + else msg+= '\n';
  142 + }
  143 + digitalWrite(out3, LOW);
  144 + delay(50);
  145 + }
  146 +
  147 + else if(digitalRead(in4)==HIGH){
  148 + digitalWrite(out4,HIGH);
  149 + timeout=0;
  150 + tps=millis();
  151 + while(Serial.available()<=0 && timeout<1000){
  152 + timeout= millis() - tps;
  153 + }
  154 + if(timeout<1000){
  155 + fin4=1;
  156 + while(inByte != '\n'){
  157 + inByte = Serial.read();
  158 + if(inByte !='\n'){
  159 + msg += inByte;
  160 + delay(10);
  161 + }
  162 + }
  163 + if(prem==0){
  164 + prem=1;
  165 + papa=4;
  166 + msg += id;
  167 + if((id & 0xF0) ==0x60) msg += '{'; //char pour 123
  168 + else if((id & 0xF0) ==0x40) msg += 0b00000100;
  169 + msg += '\n';
  170 + }
  171 + else msg+= '\n';
  172 + }
  173 + digitalWrite(out4, LOW);
  174 + delay(50);
  175 + }
  176 +
  177 + if(fin1==1 || fin2==1 || fin3==1 || fin4==1){
  178 + if((fin1==1 && papa == 1) || (fin1 == 0)){
  179 + timeout=0;
  180 + tps = millis();
  181 + while(timeout<1000){
  182 + digitalWrite(out1,HIGH);
  183 + timeout= millis() - tps;
  184 + if(fin1==1) timeout=0;
  185 + if(digitalRead(in1)==HIGH){
  186 + soft1.print(msg);
  187 + soft1.flush();
  188 + timeout = 1001;
  189 + }
  190 + }
  191 + digitalWrite(out1,LOW);
  192 + }
  193 +
  194 + if((fin2==1 && papa == 2) || (fin2 == 0)){
  195 + timeout=0;
  196 + tps = millis();
  197 + while(timeout<1000){
  198 + digitalWrite(out2,HIGH);
  199 + timeout= millis() - tps;
  200 + if(fin2==1) timeout=0;
  201 + if(digitalRead(in2)==HIGH){
  202 + soft2.print(msg);
  203 + soft2.flush();
  204 + digitalWrite(out2,LOW);
  205 + timeout = 1001;
  206 + }
  207 + }
  208 + digitalWrite(out2,LOW);
  209 + }
  210 +
  211 +
  212 + if((fin3==1 && papa == 3) || (fin3 == 0)){
  213 + timeout=0;
  214 + tps = millis();
  215 + while(timeout<1000){
  216 + digitalWrite(out3,HIGH);
  217 + timeout= millis() - tps;
  218 + if(fin3==1) timeout=0;
  219 + if(digitalRead(in3)==HIGH){
  220 + soft3.print(msg);
  221 + soft3.flush();
  222 + digitalWrite(out3,LOW);
  223 + timeout = 1001;
  224 + }
  225 + }
  226 + digitalWrite(out3,LOW);
  227 + }
  228 +
  229 + if((fin4==1 && papa == 4) || (fin4 == 0)){
  230 + timeout=0;
  231 + tps = millis();
  232 + while(timeout<1000){
  233 + digitalWrite(out4,HIGH);
  234 + timeout= millis() - tps;
  235 + if(fin4==1) timeout=0;
  236 + if(digitalRead(in4)==HIGH){
  237 + Serial.print(msg);
  238 + Serial.flush();
  239 + digitalWrite(out4,LOW);
  240 + timeout = 1001;
  241 + }
  242 + }
  243 + digitalWrite(out4,LOW);
  244 + }
  245 + }
  246 +}
0 247 \ No newline at end of file
... ...