LucasEloi

Transmissor v1

May 16th, 2019
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <SoftwareSerial.h>
  2.  
  3. SoftwareSerial apc220(6, 7);
  4. const int pino_botao = 4;
  5. int valor_botao;
  6. unsigned x = 0;
  7. int cont =6;
  8. int aux_cont1 = 1, aux_cont2 = 1, aux_cont3 = 1, aux_cont4 = 1, aux_cont5 = 1;
  9. unsigned long time1 = 0, time2 = 0, time3 = 0;
  10.  
  11. void setup() {
  12. Serial.begin(9600);
  13. apc220.begin(9600);
  14. pinMode(pino_botao,INPUT);
  15. // delay(100);
  16. }
  17.  
  18. void loop(){
  19.  
  20. if(digitalRead(4)==1){  // se o botão for pressionado
  21.     cont++;  // atribui +1 a variavel cont
  22.     delay(700); // da um tempo para o pressionamento, senao o arduino endoida
  23.  }
  24.  if(cont==6){cont=1;}   //  deixa o valor somente de 1 a 3
  25.  
  26.  
  27.  if(cont==1){
  28.   time1 = millis();
  29.   while (aux_cont1 == 1) {
  30.  apc220.write(10);
  31.  time2 = millis();
  32.   Serial.println(cont);
  33. delay(10);
  34. if ((time2 - time1) > 5000)
  35.         aux_cont1 = 0;
  36.   }
  37.  }
  38.  else if(cont==2){
  39.   time1 = millis();
  40.     while (aux_cont2 == 1) {
  41.   apc220.write(50);
  42.   Serial.println(cont);  
  43. delay(10);
  44. time2 = millis();
  45.       if ((time2 - time1) > 5000)
  46.         aux_cont2 = 0;
  47.     }
  48.  }
  49.  else if(cont==3){
  50.   time1 = millis();
  51.     while (aux_cont3 == 1) {
  52.   apc220.write(100);
  53.   Serial.println(cont);
  54. delay(10);
  55. time2 = millis();
  56.       if ((time2 - time1) > 5000)
  57.         aux_cont3 = 0;
  58.  }}
  59.  else if(cont==4){
  60.   time1 = millis();
  61.     while (aux_cont4 == 1) {
  62.   apc220.write("5");
  63.   Serial.println(cont);
  64.  
  65. time2 = millis();
  66.       if ((time2 - time1) > 5000)
  67.         aux_cont4 = 0;
  68.     }
  69.  }
  70.  else if(cont==5){
  71.   time1 = millis();
  72.     while (aux_cont5 == 1) {
  73.   apc220.write("0");
  74.   Serial.println(cont);
  75.  
  76. time2 = millis();
  77.       if ((time2 - time1) > 5000)
  78.         aux_cont5 = 0;
  79.  }
  80. }
  81.  
  82. }
Advertisement
Add Comment
Please, Sign In to add comment