Hey guys,
I am creating an e-textile garment using heating pads and a flora microcontroller (adrafruit). I want to specify an action every 5 minutes. I am using a DS1338 RTC. currently I am using a switch to create a connection between the power supply and the flora. I want the flora to retrieve the the time from the RTC and increment by 5 every cycle. for example 13:05 --> action 13:10 --> stops action 13:15 --> (action).
I am currently using the following libraries:
#include <Arduino.h>
#include <Wire.h>
#include "RTClib.h"
currently I can retrieve the time from RTC and create an action at a specified time and turn it off at a specific time. I have also looked into time alarms. However there doesn't seem to be a function for minutes, only seconds and milliseconds. TimeAlarms Library, Run Functions At Specific Times
Does anyone have an suggestions?
currently I can retrieve the time from RTC and create an action at a specified time and turn it off at a specific time.
So what is the problem?
For informed help with specific problems, follow the directions in the "How to use this forum" post and post the code, using code tags, and tell us what goes wrong.
#include <Arduino.h>
#include <Wire.h> // this #include still required because the RTClib depends on it
#include "RTClib.h"
#if defined(ARDUINO_ARCH_SAMD)
#define Serial
#endif
RTC_Millis rtc;
#include <Time.h>
#include <TimeAlarms.h>
int btnPin = 2; //input
int fetPin1 = 6; //outputs
int fetPin2 = 12;
int fetPin3 = 9;
int fetPin4= 10;
int reading; //the current reading from the input pin
int previous = LOW; //previous reading from the input pin
void setup() {
Serial1.begin(57600);
rtc.begin(DateTime(F(__DATE__), F(__TIME__)));
pinMode(btnPin, INPUT); //input trigger i.e snap switch
pinMode(fetPin1, OUTPUT); //output trigger i.e the 4 heating pads
pinMode(fetPin2, OUTPUT);
pinMode(fetPin3, OUTPUT);
pinMode(fetPin4, OUTPUT);
//Alarm.timerRepeat(300, heating_on); //300 = 5 minutes
//Alarm.timerRepeat(602, heating_off); //600 = 10 minutes
}
// the loop routine runs over and over again forever:
void loop() {
reading = digitalRead(btnPin);
if (reading == HIGH && previous == LOW){ //if button pin is equal to 1 and previous reading is equal to 0
DateTime now = rtc.now();
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();
Alarm.timerRepeat(60, heating_on);
Alarm.timerRepeat(125, heating_off);
}
}
void heating_on(){
digitalWrite(fetPin1, HIGH);
digitalWrite(fetPin2, HIGH);
digitalWrite(fetPin3, HIGH);
digitalWrite(fetPin4, HIGH);
}
void heating_off(){
digitalWrite(fetPin1, LOW);
digitalWrite(fetPin2, LOW);
digitalWrite(fetPin3, LOW);
digitalWrite(fetPin4, LOW);
}
Hey heres my code...The heating pads automatically turn on and arn't controlled by time. I don't know wheat i'm doing wrong.
Any help would be appreciated.
I basically want the time alarms to trigger the heating pads on and off...
You aren't using the library correctly.
Alarm.timerRepeat() creates a new alarm function, and should be in setup(), not loop().
Also, if you have one function turning the heater on every 5 minutes, and another turning it off every 10 minutes, then every 10 minutes they will conflict with each other.
Unless the timing must be very accurate, you may be better off using millis(), following the basic examples "blink without delay" or "how to do several things at once".
Thank you!
I will give that i go now and i will also change the timings, as previously I was using the serial monitor to test functionality.
Unfortunately I can't use millis() i need to use the RTC to retrieve the time and then carry out the function...