/*
Laboratorio de prueba 8
Crhistian Lucumi
*/
#include <SPI.h>
#include <Adafruit_GFX.h> //https://github.com/adafruit/Adafruit-GFX-Library
#include <Adafruit_PCD8544.h> //https://github.com/adafruit/Adafruit-PCD8544-Nokia-5110-LCD-library
int rele = 13;
int sensor = 2;
boolean movimiento = false;
// Software SPI (slower updates, more flexible pin options):
// pin 7 - Serial clock out (SCLK)
// pin 6 - Serial data out (DIN)
// pin 5 - Data/Command select (D/C)
// pin 4 - LCD chip select (CS)
// pin 3 - LCD reset (RST)
Adafruit_PCD8544 display = Adafruit_PCD8544(7, 6, 5, 4, 3); //visto en el ejemplo pcbtest de la libreria Adafruit-PCD8544-Nokia-5110-LCD-library
void setup() {
// put your setup code here, to run once:
pinMode(rele, OUTPUT);
attachInterrupt(digitalPinToInterrupt(sensor), detectado, RISING);
display.begin();
// init done
// you can change the contrast around to adapt the display
// for the best viewing!
display.setContrast(60);
display.display(); // show splashscreen
delay(2000);
display.clearDisplay(); // clears the screen and buffer
Serial.begin(9600);
}
int cambio = 1;
void loop() {
// put your main code here, to run repeatedly:
Serial.println(digitalRead(sensor));
if(movimiento){
activeSwitch();
if (cambio != 2){
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(BLACK);
display.setCursor(0,0);
display.println("Si Me\nMuevo");
display.display();
cambio=2;
}
}
if(digitalRead(sensor) == LOW){
movimiento = false;
if (cambio == 2){
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(BLACK);
display.setCursor(0,0);
display.println("No Me\nMuevo");
display.display();
cambio=1;
}
deactiveSwitch();
}
}
void detectado(){
movimiento = true;
}
void activeSwitch(){
digitalWrite(rele, LOW);
}
void deactiveSwitch(){
digitalWrite(rele, HIGH);
}