Skip to content

Instantly share code, notes, and snippets.

@nikibobi
Last active April 2, 2018 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nikibobi/92f803a1e8acc309356e to your computer and use it in GitHub Desktop.
Save nikibobi/92f803a1e8acc309356e to your computer and use it in GitHub Desktop.
#define T 30
#define PIN_START 3
#define PIN_TOP 4
#define PIN_BOT 5
#define PIN_DOWN 7
#define PIN_UP 9
void setup() {
pinMode(PIN_START, INPUT);
pinMode(PIN_TOP, INPUT);
pinMode(PIN_BOT, INPUT);
pinMode(PIN_DOWN, OUTPUT);
pinMode(PIN_UP, OUTPUT);
goNo();
}
void loop() {
if(digitalRead(PIN_START) == LOW)
return;
goDown();//start going down
while(digitalRead(PIN_BOT) == LOW);//untill we hit rock bottom
goNo();//then stop
delay(T * 1000);//then wait T seconds
goUp();//start going up
while(digitalRead(PIN_TOP) == LOW);//untill we hit sky top
goNo();//and stop
}
void goDown() {
digitalWrite(PIN_UP, LOW);
digitalWrite(PIN_DOWN, HIGH);
}
void goUp() {
digitalWrite(PIN_DOWN, LOW);
digitalWrite(PIN_UP, HIGH);
}
void goNo() {
digitalWrite(PIN_DOWN, LOW);
digitalWrite(PIN_UP, LOW);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment