Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define Pin_paraquedas 12
- #define pinTA 3
- #define pinRM 2
- #define pinTZ A1
- #define BUZZER 11
- unsigned long Sensor_tempo = 0;
- unsigned long Debouce_tempo = 0;
- bool state = false;
- bool Veri_bool = false;
- int Val_sensor[3];
- volatile int i = 0;
- volatile int teste = 0;
- volatile int acionador = 0;
- int Estado_apogeu = 0;
- volatile int verificador = 0;
- volatile int k = 0;
- volatile int acionador1 = 0;
- bool stateb = false;
- void interrupt_TA() {
- digitalWrite(13, HIGH);
- k = k + 1;
- if (k == 1) {
- Val_sensor[0] = digitalRead(pinRM);
- Val_sensor[1] = digitalRead(pinTA);
- verificador = analogRead(pinTZ);
- if (verificador < 700) {
- Val_sensor[2] = 1;
- }
- else {
- Val_sensor[2] = 0;
- }
- for (int j = 0; j < 3; j++) {
- teste = Val_sensor[j];
- Serial.println( teste);
- if (teste == 1 ) {//está dando problema aqui pq quando os analógicos são 0<700 e entra desativado)
- acionador1 = acionador1 + 1;
- }
- }
- if (acionador1 >= 2) {
- stateb = true;
- }
- else {
- k = 0;
- acionador1 = 0;
- }
- }
- else {
- stateb = false;
- k = 0;
- acionador1 = 0;
- }
- }
- void interrupt_RM() {
- digitalWrite(13, HIGH);
- i = i + 1;
- if (i == 1) {
- Val_sensor[0] = digitalRead(pinRM);
- Val_sensor[1] = digitalRead(pinTA);
- verificador = analogRead(pinTZ);
- if (verificador < 700) {
- Val_sensor[2] = 1;
- }
- else {
- Val_sensor[2] = 0;
- }
- for (int j = 0; j < 3; j++) {
- teste = Val_sensor[j];
- Serial.println( teste);
- if (teste == 1 ) {//está dando problema aqui pq quando os analógicos são 0<700 e entra desativado)
- acionador = acionador + 1;
- }
- }
- if (acionador >= 2) {
- state = true;
- }
- else {
- i = 0;
- acionador = 0;
- }
- }
- else {
- state = false;
- i = 0;
- acionador = 0;
- }
- }
- void setup() {
- pinMode(pinTA, INPUT);
- pinMode(pinTZ, INPUT);
- pinMode(pinRM, INPUT);
- pinMode(Pin_paraquedas, OUTPUT);
- pinMode(BUZZER, OUTPUT);
- pinMode(13, OUTPUT);
- attachInterrupt(digitalPinToInterrupt(2), interrupt_RM, CHANGE);
- attachInterrupt(digitalPinToInterrupt(3), interrupt_TA, CHANGE);
- Serial.begin(9600);
- int Estado_apogeu = 0;
- digitalWrite(pinRM , LOW);
- digitalWrite(pinTA, LOW);
- digitalWrite(Pin_paraquedas, LOW);
- while (digitalRead(pinTA)) {
- tone(BUZZER, 984);
- }
- while (digitalRead(pinRM)) {
- tone(BUZZER, 4000);
- }
- while (analogRead(pinTZ) <= 750) {
- tone(BUZZER, 2500);
- }
- }
- void loop() {
- digitalWrite(13, LOW);
- if (state == true || stateb == true) {
- if (!Veri_bool) {
- Sensor_tempo = millis();
- Veri_bool = true;
- }
- Debouce_tempo = millis() - Sensor_tempo;
- if (Debouce_tempo > 3000 && stateb == true) {
- Estado_apogeu = 1;
- }
- if (Debouce_tempo > 3000 && state == true) {
- Estado_apogeu = 1;
- }
- }
- if (state == false && stateb == false ) {
- Estado_apogeu = 0;
- Veri_bool = false;
- }
- digitalWrite(Pin_paraquedas, Estado_apogeu);
- //Serial.println(digitalRead(pinRM));
- //Serial.print(digitalRead(pinTA));
- //Serial.println(analogRead(pinTZ));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement