Skip to content

Instantly share code, notes, and snippets.

@technobly
Created August 11, 2016 03:28
Show Gist options
  • Save technobly/501fccdafe413c4dd9551b12ef2e06ad to your computer and use it in GitHub Desktop.
Save technobly/501fccdafe413c4dd9551b12ef2e06ad to your computer and use it in GitHub Desktop.
Photon Relay Shield Cycler
int onTime = 30000;
int offTime = 300000;
int cycles = 0;
bool isOn = true;
uint32_t startTime = millis();
int updateOnTime(String command){
onTime = command.toInt();
return onTime;
}
int updateOffTime(String command){
offTime = command.toInt();
return offTime;
}
int updateCycles(String command){
cycles = command.toInt();
return cycles;
}
void setup() {
Particle.function("updateOn", updateOnTime);
Particle.function("updateOff", updateOffTime);
Particle.function("updateCyc", updateCycles);
Particle.variable("cycles", &cycles, INT);
Particle.variable("on", &onTime, INT);
Particle.variable("off", &offTime, INT);
pinMode(D0, OUTPUT);
pinMode(D1, OUTPUT);
pinMode(D2, OUTPUT);
pinMode(D3, OUTPUT);
startTime = millis();
digitalWrite(D0, HIGH); // turn it on!
}
void loop() {
uint32_t now = millis();
if (isOn && now - startTime > (uint32_t)onTime) {
digitalWrite(D0, LOW); // turn it off!
startTime = now;
isOn = false;
cycles++;
}
else if (!isOn && now - startTime > (uint32_t)offTime) {
digitalWrite(D0, HIGH); // turn it on!
startTime = now;
isOn = true;
}
delay(1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment