Created
September 11, 2017 14:21
-
-
Save jordanskole/18eb86ec8633696ff021a4df0d2ac5ab to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int RELAY1 = D3; | |
int RELAY2 = D4; | |
int RELAY3 = D5; | |
int RELAY4 = D6; | |
void setup() | |
{ | |
//Initilize the relay control pins as output | |
pinMode(RELAY1, OUTPUT); | |
pinMode(RELAY2, OUTPUT); | |
pinMode(RELAY3, OUTPUT); | |
pinMode(RELAY4, OUTPUT); | |
// Initialize all relays to an OFF state | |
digitalWrite(RELAY1, LOW); | |
digitalWrite(RELAY2, LOW); | |
digitalWrite(RELAY3, LOW); | |
digitalWrite(RELAY4, LOW); | |
//register the Particle function | |
Particle.function("goal", ringTheAlarm); | |
} | |
// This loops for ever | |
void loop() | |
{ | |
} | |
int ringTheAlarm(String seconds) | |
{ int secondsAsInt = atoi(seconds); | |
if (secondsAsInt < 10 && secondsAsInt > 0) { | |
int secondsAsSeconds = secondsAsInt * 1000; | |
digitalWrite(RELAY1, HIGH); | |
delay(secondsAsSeconds); | |
digitalWrite(RELAY1, LOW); | |
return 1; | |
} else { | |
digitalWrite(RELAY1, HIGH); | |
delay(3000); | |
digitalWrite(RELAY1, LOW); | |
return 1; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment