Advertisement
Guest User

Código atualizado helena 23\01

a guest
Jan 23rd, 2020
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.24 KB | None | 0 0
  1. #define Pin_paraquedas 12
  2. #define pinTA 3
  3. #define pinRM 2
  4. #define pinTZ A1
  5. #define BUZZER 11
  6. unsigned long Sensor_tempo = 0;
  7. unsigned long Debouce_tempo = 0;
  8. bool state = false;
  9. bool Veri_bool = false;
  10. int Val_sensor[3];
  11. volatile int i = 0;
  12. volatile int teste = 0;
  13. volatile int acionador = 0;
  14. int Estado_apogeu = 0;
  15. volatile int verificador = 0;
  16. volatile int k = 0;
  17. volatile int acionador1 = 0;
  18. bool stateb = false;
  19. void interrupt_TA() {
  20.  
  21.   digitalWrite(13, HIGH);
  22.   k = k + 1;
  23.  
  24.   if (k == 1) {
  25.  
  26.     Val_sensor[0] = digitalRead(pinRM);
  27.     Val_sensor[1] = digitalRead(pinTA);
  28.     verificador = analogRead(pinTZ);
  29.     if (verificador < 700) {
  30.       Val_sensor[2] = 1;
  31.     }
  32.     else {
  33.       Val_sensor[2] = 0;
  34.     }
  35.  
  36.     for (int j = 0; j < 3; j++) {
  37.       teste = Val_sensor[j];
  38.       Serial.println( teste);
  39.       if (teste == 1  ) {//está dando problema aqui pq quando os analógicos são 0<700 e entra desativado)
  40.  
  41.  
  42.         acionador1 = acionador1 + 1;
  43.  
  44.       }
  45.     }
  46.     if (acionador1 >= 2) {
  47.       stateb = true;
  48.     }
  49.     else {
  50.       k = 0;
  51.  
  52.       acionador1 = 0;
  53.     }
  54.  
  55.   }
  56.   else {
  57.     stateb = false;
  58.     k = 0;
  59.  
  60.     acionador1 = 0;
  61.   }
  62. }
  63.  
  64.  
  65. void interrupt_RM() {
  66.   digitalWrite(13, HIGH);
  67.   i = i + 1;
  68.  
  69.   if (i == 1) {
  70.  
  71.     Val_sensor[0] = digitalRead(pinRM);
  72.     Val_sensor[1] = digitalRead(pinTA);
  73.     verificador = analogRead(pinTZ);
  74.     if (verificador < 700) {
  75.       Val_sensor[2] = 1;
  76.     }
  77.     else {
  78.       Val_sensor[2] = 0;
  79.     }
  80.  
  81.     for (int j = 0; j < 3; j++) {
  82.       teste = Val_sensor[j];
  83.       Serial.println( teste);
  84.       if (teste == 1  ) {//está dando problema aqui pq quando os analógicos são 0<700 e entra desativado)
  85.  
  86.  
  87.         acionador = acionador + 1;
  88.  
  89.       }
  90.     }
  91.     if (acionador >= 2) {
  92.       state = true;
  93.     }
  94.     else {
  95.  
  96.       i = 0;
  97.       acionador = 0;
  98.     }
  99.  
  100.   }
  101.   else {
  102.     state = false;
  103.  
  104.     i = 0;
  105.     acionador = 0;
  106.   }
  107. }
  108.  
  109. void setup() {
  110.   pinMode(pinTA, INPUT);
  111.   pinMode(pinTZ, INPUT);
  112.   pinMode(pinRM, INPUT);
  113.   pinMode(Pin_paraquedas, OUTPUT);
  114.   pinMode(BUZZER, OUTPUT);
  115.   pinMode(13, OUTPUT);
  116.   attachInterrupt(digitalPinToInterrupt(2), interrupt_RM, CHANGE);
  117.   attachInterrupt(digitalPinToInterrupt(3), interrupt_TA, CHANGE);
  118.   Serial.begin(9600);
  119.   int Estado_apogeu = 0;
  120.   digitalWrite(pinRM , LOW);
  121.   digitalWrite(pinTA, LOW);
  122.   digitalWrite(Pin_paraquedas, LOW);
  123.   while (digitalRead(pinTA)) {
  124.     tone(BUZZER, 984);
  125.   }
  126.   while (digitalRead(pinRM)) {
  127.     tone(BUZZER, 4000);
  128.   }
  129.   while (analogRead(pinTZ) <= 750) {
  130.     tone(BUZZER, 2500);
  131.   }
  132. }
  133.  
  134.  
  135.  
  136.  
  137.  
  138. void loop() {
  139.   digitalWrite(13, LOW);
  140.   if (state == true || stateb == true) {
  141.     if (!Veri_bool) {
  142.       Sensor_tempo = millis();
  143.       Veri_bool = true;
  144.  
  145.     }
  146.     Debouce_tempo = millis() - Sensor_tempo;
  147.     if (Debouce_tempo > 3000 && stateb == true) {
  148.       Estado_apogeu = 1;
  149.     }
  150.     if (Debouce_tempo > 3000 && state == true) {
  151.       Estado_apogeu = 1;
  152.  
  153.     }
  154.   }
  155.   if (state == false && stateb == false ) {
  156.     Estado_apogeu = 0;
  157.     Veri_bool = false;
  158.   }
  159.  
  160.   digitalWrite(Pin_paraquedas, Estado_apogeu);
  161.  
  162.   //Serial.println(digitalRead(pinRM));
  163.   //Serial.print(digitalRead(pinTA));
  164.   //Serial.println(analogRead(pinTZ));
  165. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement