Paso 3: Parte 1: codificación
---------------------------------------------------------------------
const int sensor_pin = 7;
int prepTime = 30;
tiempo unsigned int lowIn;
pausa larga unsigned int = 5000;
Boolean lockLow = true;
takeLowTime Boolean;
pirPin int = 7;
int ledPin = 5;
PROGRAMA DE INSTALACIÓN
void setup() {}
Serial.Begin(9600);
pinMode (pirPin, entrada);
pinMode (ledPin, salida);
digitalWrite (pirPin, LOW);
Serial.Print ("preparación de sensor");
para (int i = 0; i < prepTime; i ++) {}
Serial.Print(".");
Delay(1000);
}
Serial.println ("hecho");
Serial.println ("SENSOR activo");
Delay(50);
}
LAZO
void loop() {}
if(digitalRead(pirPin) == HIGH) {}
digitalWrite (ledPin, HIGH);
{if(lockLow)}
lockLow = false;
Serial.println("---");
Serial.Print ("movimiento detectado en");
Serial.Print(Millis()/1000);
Serial.println ("sec");
Delay(50);
}
takeLowTime = true;
}
if(digitalRead(pirPin) == LOW) {}
digitalWrite (ledPin, LOW);
{if(takeLowTime)}
lowIn = millis();
takeLowTime = false;
}
Si (! lockLow & & millis() - lowIn > pausa) {}
lockLow = true;
Serial.Print ("movimiento terminada en");
Serial.Print((Millis() - pausa) / 1000);
Serial.println ("sec");
Delay(50);
}
}
}
---------------------------------------------------------------------