Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. /*
  2.   Laboratorio de prueba 8
  3.   Crhistian Lucumi  
  4. */
  5.  
  6. #include <SPI.h>
  7. #include <Adafruit_GFX.h> //https://github.com/adafruit/Adafruit-GFX-Library
  8. #include <Adafruit_PCD8544.h> //https://github.com/adafruit/Adafruit-PCD8544-Nokia-5110-LCD-library
  9.  
  10.  
  11. int rele = 13;
  12. int sensor = 2;
  13. boolean movimiento = false;
  14. // Software SPI (slower updates, more flexible pin options):
  15. // pin 7 - Serial clock out (SCLK)
  16. // pin 6 - Serial data out (DIN)
  17. // pin 5 - Data/Command select (D/C)
  18. // pin 4 - LCD chip select (CS)
  19. // pin 3 - LCD reset (RST)
  20.   Adafruit_PCD8544 display = Adafruit_PCD8544(7, 6, 5, 4, 3); //visto en el ejemplo pcbtest de la libreria Adafruit-PCD8544-Nokia-5110-LCD-library
  21.  
  22. void setup() {
  23.   // put your setup code here, to run once:
  24.   pinMode(rele, OUTPUT);
  25.   attachInterrupt(digitalPinToInterrupt(sensor), detectado, RISING);
  26.   display.begin();
  27.   // init done
  28.  
  29.   // you can change the contrast around to adapt the display
  30.   // for the best viewing!
  31.   display.setContrast(60);
  32.  
  33.   display.display(); // show splashscreen
  34.   delay(2000);
  35.   display.clearDisplay();   // clears the screen and buffer
  36.  
  37.   Serial.begin(9600);
  38.  
  39.  
  40. }
  41. int cambio = 1;
  42. void loop() {
  43.   // put your main code here, to run repeatedly:
  44.   Serial.println(digitalRead(sensor));
  45.   if(movimiento){
  46.     activeSwitch();
  47.     if (cambio != 2){
  48.         display.clearDisplay();
  49.         display.setTextSize(2);
  50.         display.setTextColor(BLACK);
  51.         display.setCursor(0,0);
  52.         display.println("Si Me\nMuevo");
  53.         display.display();
  54.         cambio=2;
  55.     }
  56.   }
  57.   if(digitalRead(sensor) == LOW){
  58.     movimiento = false;
  59.     if (cambio == 2){
  60.         display.clearDisplay();
  61.         display.setTextSize(2);
  62.           display.setTextColor(BLACK);
  63.           display.setCursor(0,0);
  64.           display.println("No Me\nMuevo");
  65.           display.display();
  66.           cambio=1;
  67.     }
  68.     deactiveSwitch();
  69.   }
  70. }
  71. void detectado(){
  72.     movimiento = true;
  73. }
  74. void activeSwitch(){
  75.     digitalWrite(rele, LOW);
  76. }
  77. void deactiveSwitch(){
  78.     digitalWrite(rele, HIGH);
  79. }