#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Adafruit_NeoPixel.h>
#include <Servo.h>
#define buzzerPIN 3
#define servoPIN 6
#define pirPIN 8
#define neoPIN 12
#define NUMPIXELS 16
#define DS1307_ADDRESS 0x68
// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27, 16, 2);
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUMPIXELS, neoPIN, NEO_GRB + NEO_KHZ800);
Servo myservo;
void pinDirs() {
pinMode(pirPIN, INPUT);
pinMode(neoPIN, OUTPUT);
pinMode(buzzerPIN,OUTPUT);
}
void colorWipe(uint32_t c, uint8_t wait) {
for(uint16_t i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, c);
strip.show();
delay(wait);
}
}
uint8_t bcdToDec(uint8_t value)
{
// Converts from BCD to decimal
return ((value / 16 * 10) + (value % 16));
}
void getTime() {
Wire.beginTransmission(DS1307_ADDRESS);
Wire.write(0x00);
Wire.endTransmission();
Wire.requestFrom(DS1307_ADDRESS, 0x07);
uint8_t seconds = bcdToDec(Wire.read());
uint8_t minutes = bcdToDec(Wire.read());
uint8_t hours = bcdToDec(Wire.read() & 0xff);
uint8_t wday = bcdToDec(Wire.read());
uint8_t mday = bcdToDec(Wire.read());
uint8_t month = bcdToDec(Wire.read());
uint8_t year = bcdToDec(Wire.read());
// Shows the data on the display
lcd.setCursor(0,1);
lcd.print("Time is ");
// Adds 0 (clear) if the time is less than 10
if (hours < 10)
lcd.print("0");
lcd.print(hours);
if (seconds & 1)
lcd.print(":");
else
lcd.print(" ");
// Adds 0 (clear) if minutes are less than 10
if (minutes < 10)
lcd.print("0");
lcd.print(minutes);
if (seconds & 1)
lcd.print(":");
else
lcd.print(" ");
if (seconds < 10)
lcd.print("0");
lcd.print(seconds);
}
void setup()
{
Wire.begin();
lcd.init();
lcd.backlight();
strip.begin();
myservo.attach(servoPIN);
lcd.println("...setting up....");
colorWipe(strip.Color(0, 0, 255), 50); // blue
myservo.write(0); // tell servo to go to position in variable 'pos'
delay(15);
// Initialize the serial port at a speed of 9600 baud
Serial.begin(9600);
Serial.println("LCD I2C Example: ");
}
void loop()
{
lcd.clear();
if (digitalRead(pirPIN)==LOW){
lcd.setCursor(0,0);
lcd.println("you have escaped");
getTime();
digitalWrite(buzzerPIN, HIGH);
myservo.write(90); // tell servo to go to position in variable 'pos'
colorWipe(strip.Color(255, 0, 0), 50); // Green
} else {
lcd.setCursor(0,0);
lcd.println("I can see you!!");
getTime();
digitalWrite(buzzerPIN, LOW);
myservo.write(180); // tell servo to go to position in variable 'pos'
colorWipe(strip.Color(0, 255, 0), 50); // Green
}
delay(1000);
}
uno:A5.2
uno:A4.2
uno:AREF
uno:GND.1
uno:13
uno:12
uno:11
uno:10
uno:9
uno:8
uno:7
uno:6
uno:5
uno:4
uno:3
uno:2
uno:1
uno:0
uno:IOREF
uno:RESET
uno:3.3V
uno:5V
uno:GND.2
uno:GND.3
uno:VIN
uno:A0
uno:A1
uno:A2
uno:A3
uno:A4
uno:A5
lcd1:GND
lcd1:VCC
lcd1:SDA
lcd1:SCL
pir1:VCC
pir1:OUT
pir1:GND
ring1:GND
ring1:VCC
ring1:DIN
ring1:DOUT
servo1:GND
servo1:V+
servo1:PWM
bz1:1
bz1:2
rtc1:GND
rtc1:5V
rtc1:SDA
rtc1:SCL
rtc1:SQW