fasdfsa

mail@pastecode.io avatar
unknown
c_cpp
2 years ago
1.4 kB
2
Indexable
Never
const int rojo=2; //Se declaran constantes
const int verde=3;
const int sensor=4;
const int validacion=8;
const int interruptor=5;
const int interruptor2=6;
const int interruptor3=7;
const int piezo=9;

int alarma = 0;

void setup()
{
  pinMode(interruptor, OUTPUT);
  pinMode(interruptor2, OUTPUT);
  pinMode(interruptor3, OUTPUT);
  
  pinMode(piezo, OUTPUT);
  pinMode(verde, OUTPUT);
  pinMode(rojo, OUTPUT);
  pinMode(sensor, INPUT_PULLUP);
  pinMode(validacion, INPUT_PULLUP);
  Serial.begin(9600); 
}

void loop()
{
  int sensorVal = digitalRead(sensor);
  int validacionVal = digitalRead(validacion);
  int interruptorVal = digitalRead(interruptor);
  int interruptor2Val = digitalRead(interruptor2);
  int interruptor3Val = digitalRead(interruptor3);


  
  if(sensorVal == 0){
    alarma = 1;
  }
  if(alarma == 0){
    digitalWrite(verde, HIGH);
    digitalWrite(rojo, LOW);
    digitalWrite(piezo, 0);
  }
  if(alarma == 1){
    digitalWrite(verde, LOW);
    digitalWrite(rojo, HIGH);
    digitalWrite(piezo, 1);
    
  }
  
  if(validacionVal == 0){
    if(interruptorVal == 1 && 
       interruptor2Val == 0 && 
       interruptor3Val == 1){
      alarma = 0;
    }
    else{
      alarma = 1;    
    }
  }
  Serial.println(validacionVal);
  Serial.println(sensorVal);
  /*Serial.println(alarma);
  Serial.println(sensorVal);
  Serial.println(validacionVal);*/
}