Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SoftwareSerial.h>
- #include <Wire.h>
- #include "RTClib.h"
- SoftwareSerial bluetooth(0, 1);
- char charr;
- RTC_DS1307 rtc;
- void setup() {
- // put your setup code here, to run once:
- pinMode(8, OUTPUT);
- bluetooth.begin(9600);
- digitalWrite(8, HIGH);
- Serial.begin(9600);
- if (! rtc.begin()) {
- Serial.println("Couldn't find RTC");
- while (1);
- }
- if (! rtc.isrunning()) {
- Serial.println("RTC is NOT running!");
- // following line sets the RTC to the date & time this sketch was compiled
- rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
- // This line sets the RTC with an explicit date & time, for example to set
- // January 21, 2014 at 3am you would call:
- // rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
- }
- }
- boolean startHourDone = false;
- boolean startMinutDone = false;
- String startHour;
- String startMinut;
- boolean stopHourDone = false;
- boolean stopMinutDone = false;
- String stopHour;
- String stopMinut;
- void loop() {
- // put your main code here, to run repeatedly:
- DateTime now = rtc.now();
- /*if(now.minute() == 43){
- digitalWrite(8,HIGH);
- }*/
- if(bluetooth.available()){
- charr = bluetooth.read();
- if(startHourDone == false){
- if(charr == ':'){
- startHourDone = true;
- return;
- }
- startHour += charr;
- }else if(startHourDone == true && startMinutDone == false){
- if(charr == ':'){
- startMinutDone = true;
- return;
- }
- startMinut += charr;
- }else if(startHourDone == true && startMinutDone == true && stopHourDone == false){
- if(charr == ':'){
- stopHourDone = true;
- return;
- }
- stopHour += charr;
- }
- else if(startHourDone == true && startMinutDone == true && stopHourDone == true && stopMinutDone == false){
- if(charr == ':'){
- stopMinutDone = true;
- return;
- }
- stopMinut += charr;
- }
- Serial.println("START : HOUR: " + startHour + " MINUT: " + startMinut);
- Serial.println("STOP : HOUR: " + stopHour + " MINUT: " + stopMinut);
- }
- if((String)now.hour() == startHour &&(String) now.minute() == startMinut){
- digitalWrite(8, LOW);
- Serial.println("OFF!");
- }else if ((String)now.hour() == stopHour &&(String) now.minute() == stopMinut){
- digitalWrite(8, HIGH);
- Serial.println("ON!");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement