Skip to content

Instantly share code, notes, and snippets.

@kyab
Last active August 29, 2015 14:09
Show Gist options
  • Select an option

  • Save kyab/d404843cc3691b823c32 to your computer and use it in GitHub Desktop.

Select an option

Save kyab/d404843cc3691b823c32 to your computer and use it in GitHub Desktop.
fanheater_runner.ino
#include <Servo.h>
Servo servo;
unsigned long start_ms;
void moveServo(){
//attach/detach each time to avoid servo noise.
servo.attach(10);
servo.write(10);
delay(1000);
servo.write(130);
delay(1000);
servo.detach();
}
void setup(){
Serial.begin(9600);
pinMode(7, INPUT);
delay(500);
moveServo();
start_ms = millis();
}
void loop(){
if ((millis() - start_ms) > (unsigned long)1000L * (unsigned long)60L * 100L){ //110 min was too short.
moveServo();
start_ms = millis();
return;
}
//check switch on
if (LOW == digitalRead(7)){
Serial.println("switch pressed");
moveServo();
}
delay(500);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment