Hey there!
I’ve been trying to implement a new function in my smart lamp project where the code would take 4 inputs from the user: start hour, start minute, end hour, and end minute in order to turn my led on during a desired duration. Whenever I’m inputting commands from the Particle app, the led refrains from turning on during the time i’ve set. I’ve attached my code below.
I think the problem has to do with the action of taking a string from the user and converting it to an int, and that being unable to be passed to the alarm function.
Any feedback would be a great help! Thanks!
// This #include statement was automatically added by the Particle IDE.
#include <TimeAlarms.h>
int flag=0;
int led=D7;
int A,B,C,D;
void powswtch()
{
if(flag==0) {
digitalWrite(led,HIGH);
flag=1;
}
else if(flag==1) {
digitalWrite(led,LOW);
flag=0;
}
}
int setA(String command) {
A = command.toInt();
return A;
}
int setB(String command) {
B = command.toInt();
return B;
}
int setC(String command) {
C = command.toInt();
return C;
}
int setD(String command) {
D = command.toInt();
return D;
}
void setup()
{
Time.zone(-5);
pinMode(led,OUTPUT);
Particle.function("startHour",setA);
Particle.function("startMinute",setB);
Particle.function("endHour",setC);
Particle.function("endMinute",setD);
Alarm.alarmRepeat(A,B,0, powswtch);
Alarm.alarmRepeat(C,D,0, powswtch);
}
void loop() {
Alarm.delay(100);
}