Good morning.
Little basic idea to my project. I'm building a basic alarm type system to start my car at 5:30/7:30/3:30 throughout the day jumping my autostart, instead of me having to physically be there. Sometimes I'm miles from it!
Here is my code so far. It's a bit wild. Basically, I have buttons to reset the time and correct it as I need because I don't have an actual timer circuit for it yet. I'm using an arduino UNO. I'm using the time library and want to start at 0 seconds for each day. After one day, I want to reset the time back to zero. I know I'll want to add in more days, but for now this is what I'm looking for. My problem is:
full_day and start_time1 act as ints. As soon as they go past the 32~~~ they go backwards. Why? I have them declared as long.
/*
* TimeSerialDateStrings.pde
* example code illustrating Time library date strings
*
* This sketch adds date string functionality to TimeSerial.pde
*
*/
#include <Time.h>
#include <LiquidCrystal.h>
#define TIME_MSG_LEN 11 // time sync to PC is HEADER followed by unix time_t as ten ascii digits
#define TIME_HEADER 'T' // Header tag for serial time sync message
#define TIME_REQUEST 7 // ASCII bell character requests a time sync message
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int switchstate = 0;
int switchstate2 = 0;
int switchstate3 = 0;
int timecheck;
int timecheck2;
unsigned long start_time1 = 0;
unsigned long full_day = 3600*24;
void setup() {
pinMode(6,INPUT);
pinMode(8,OUTPUT);
pinMode(9,INPUT);
pinMode(10,INPUT);
time_t t = now(); // Store the current time in time
// variable t
hour(t); // Returns the hour for the given
// time t
minute(t); // Returns the minute for the given
// time t
second(t); // Returns the second for the given
// time t
day(t); // The day for the given time t
weekday(t); // Day of the week for the given
// time t
month(t); // The month for the given time t
year(t); // The year for the given time t
Serial.begin(9600);
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.setCursor(0,0);
lcd.print("BIGS!!");
setTime(0);
}
void loop(){
switchstate = digitalRead(6);
switchstate2 = digitalRead(10);
switchstate3 = digitalRead(9);
if (switchstate == LOW) {
}
else {
//Serial.print("Button Pressed");
delay(100);
adjustTime(60);
}
if (switchstate2 == LOW) {
}
else {
//Serial.print("Button Pressed");
delay(100);
adjustTime(3600);
}
if (switchstate3 == LOW) {
}
else {
//Serial.print("Button Pressed");
delay(100);
setTime(0);
//setTime(hz,mz, sz, 0,0,0);
}
timecheck = now();
if (timecheck2 == timecheck) {
//Serial.print("Do Nothing");
}
else{
timecheck2 = timecheck;
lcd.clear();
lcd.setCursor(0, 1);
lcd.print(year());
lcd.print(" ");
lcd.print(hour());
lcd.print(":");
lcd.print(minute());
lcd.print(":");
lcd.print(second());
}
//6:30 am = 23400
if (now() > 23400 && now() < 23415){
digitalWrite(8,HIGH);
}
else{
digitalWrite(8,LOW);
}
//8:30 am = 30600
start_time1 = 35000 /// DOES NOT WORK
if (now() > 30600 && now() < 30615){
digitalWrite(8,HIGH);
}
else{
digitalWrite(8,LOW);
}
full_day = 86400; // THIS DOES NOT WORK
if(now() > 86400){
Serial.println("Time Reset");
setTime(0);
}
}