Well, I’ve read and Googled since yesterday. Much like when I taught myself PHP, HTML, CSS, etc. I need to ask a few questions and hopefully get some replies so I can connect my train of thought to how the code works.
I have the Internet Button. I’ve also started with an official library as it gets me a lot of the function I need. I’m connecting my button to various security things (cameras, switches, etc) for actions and notifications.
The library I’m using is in the Official Libraries - InternetButton - 9_ReleaseFirmware.CPP so I won’t copy all the code here (unless asked) as it’s easy to get to.
What I’m hoping to do, is make a function available in IFTTT that I can trigger with a motion sensor at home. I already have the connection working, so now I just need to figure out how to code my exact use case.
I’d like to have all the LEDs in the button blink (1 second on, one second off) for a set amount of time.
Bonus points for being able to set the duration in IFTTT (much like the rainbow function allows for)
Extra bonus points if I can input the duration as well as select the colour (This way I can use it for multiple alarm types, if not I can repeat the code once I know how to do it, changing the colour in the code)
It looks to me like in the setup I have to register my function (no idea if I’m using the right terms) in the block of code that starts with the comment about prototyping functions, which I did like:
// Prototypes of the functions that we'll use
int rainbowRemote(String command);
int ledOnRemote(String command);
int ledOffRemote(String command);
int ledAllOnRemote(String command);
int ledAllOffRemote(String command);
int gaugeRemote(String command);
int playSong(String command);
int motionAlarm(String command);
I then tried to smash together 2 pieces of code the each do a piece of what I need, the basic code I found for blinking all LEDs with the code for the rainbow function (as that allows for time input). I started here:
// My painful attempt to make my alarm. This is just the blinking LED
void ledMotion(){
b.allLedsOn(100,0,150);
delay(1000);
b.allLedsOff();
delay(1000);
}
// Maybe invokes the blinking LED above
int motionAlarm(String command){
char inputStr[10];
command.toCharArray(inputStr,10);
int i = atoi(inputStr);
long startMillis = millis();
while(millis() < startMillis + i*1000){
ledMotion();
}
return 1;
}
But I immediately realized that the blinky part of the code isn’t going to loop, so at best it’ll blink once.
Really, since I know so little, I don’t know how to Google to find what I need. I’d appreciate if anyone understands what I’m asking and could help with some guidance? Thanks!!