hello, i am currently working on a school project, but i seem to struggle on how i am going to properly use the weekday() function from the arduino time library (Arduino Playground - Time)
the project should be related to a smart house and i and my group decided to design a smart function where the the house will be wamer when a person wakes up and coma back from work and lower the temperature/not heating up while the person is asleep or away
NOTE: there may be other flaws in this code as well
i would appreciate any help that might solve this problem. thanks!
#include <time.h>
//#define weekday(_time_) ((( _time_ / SECS_PER_DAY + 4) % DAYS_PER_WEEK)+1) // 1 = Sunday
const int sensorPin = A0;//temp sensor
int day, hour_start, hour_stop;
int day_of_week = weekday();
/*
tmElements_t tm; // declare a time structure element
RTC.read(tm); // Read the current date & time as TimeElements variable
tm.[color=blue]Hour[/color]++; // access the hour element and increase it
if (tm.Hour > 23) tm.Hour = 0; // check for overflow, after 23h goes to 0h
RTC.write(tm); // write it back
*/
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
int pinNumber = 2; //pin 2 is connected to LED, simulates heating element
pinMode(2, OUTPUT); //-||-
digitalWrite(2, LOW); //-||-
}
void loop() {
// put your main code here, to run repeatedly:
int phone_signal = false;
int sensorVal = analogRead(sensorPin);//sensorval is bewteen 0 and 1023, value from SensorPin A0
float voltage = (sensorVal/1024.0)*5.0; //determine voltage from 0-5
float temperature = (voltage - .5)*100; //10 mV equals 1 degree celcius of change
while (phone_signal == false){
default_schedule();
}
while (phone_signal == true){
exception_time(3, 8, 15);//tuesday, warm from 8 to 15
}
}
int default_schedule(){
while (day_of_week == 2){//monday
while ((hour >= 0 and hour < 7) or (hour >=8 and hour < 15) or (hour >=22 and hour <=23)){
while (temperature < 17){
digitalWrite(2,HIGH);//simulates heating element
}
}
while ((hour >= 7 and hour < 8) or (hour >=15 and hour < 22)){
while (temperature < 21){
digitalWrite(2,HIGH);//simulates heating element
}
}
digitalWrite(2,LOW);//simulates heating element
}
while (day_of_week== 3){//tuesday
while ((hour >= 0 and hour < 7) or (hour >=8 and hour < 15) or (hour >=22 and hour <=23)){
while (temperature < 17){
digitalWrite(2,HIGH);//simulates heating element
}
}
while ((hour >= 7 and hour < 8) or (hour >=15 and hour < 22)){
while (temperature < 21){
digitalWrite(2,HIGH);//simulates heating element
}
}
digitalWrite(2,LOW);//simulates heating element
}
while (day_of_week== 4){//wednesday
while ((hour >= 0 and hour < 7) or (hour >=8 and hour < 15) or (hour >=22 and hour <=23)){
while (temperature < 17){
digitalWrite(2,HIGH);//simulates heating element
}
}
while ((hour >= 7 and hour < 8) or (hour >=15 and hour < 22)){
while (temperature < 21){
digitalWrite(2,HIGH);//simulates heating element
}
}
digitalWrite(2,LOW);//simulates heating element
}
while (day_of_week== 5){//thursday
while ((hour >= 0 and hour < 7) or (hour >=8 and hour < 15) or (hour >=22 and hour <=23)){
while (temperature < 17){
digitalWrite(2,HIGH);//simulates heating element
}
}
while ((hour >= 7 and hour < 8) or (hour >=15 and hour < 22)){
while (temperature < 21){
digitalWrite(2,HIGH);//simulates heating element
}
}
digitalWrite(2,LOW);//simulates heating element
}
while (day_of_week== 6){//friday
while ((hour >= 0 and hour < 7) or (hour >=8 and hour < 15) or (hour >=22 and hour <=23)){
while (temperature < 17){
digitalWrite(2,HIGH);//simulates heating element
}
}
while ((hour >= 7 and hour < 8) or (hour >=15 and hour < 22)){
while (temperature < 21){
digitalWrite(2,HIGH);//simulates heating element
}
}
digitalWrite(2,LOW);//simulates heating element
}
while (day_of_week== 7){//saturday
while ((hour >= 0 and hour < 7) or (hour >=22 and hour <= 23)){
while (temperature < 17){
digitalWrite(2,HIGH);//simulates heating element
}
}
while ((hour >= 7 and hour < 22)){
while (temperature < 21){
digitalWrite(2,HIGH);//simulates heating element
}
}
digitalWrite(2,LOW);//simulates heating element
}
while (day_of_week== 1){//sunday
while ((hour >= 0 and hour < 7) or (hour >=22 and hour <= 23)){
while (temperature < 17){
digitalWrite(2,HIGH);//simulates heating element
}
}
while ((hour >= 7 and hour < 22)){
while (temperature < 21){
digitalWrite(2,HIGH);//simulates heating element
}
}
digitalWrite(2,LOW);//simulates heating element
}
}
int exception_time(int day, int hour_start, int hour_stop){
/*int exception_day = day;
int exception_hours_on_start = hour_start;
int exception_hours_on_stop = hour_stop;
*/
while (day == day_of_week){
while (hour >= hour_start and hour < hour_stop){
while (temperature < 17){
digitalWrite(2,HIGH);//simulates heating element
}
}
digitalWrite(2,LOW);//simulates heating element
}
default_schedule()
}
}```