Skip to content

Instantly share code, notes, and snippets.

@aaristov
Created December 16, 2020 19:56
Show Gist options
  • Select an option

  • Save aaristov/75686ccd3c1b41941da9b17c95d097ce to your computer and use it in GitHub Desktop.

Select an option

Save aaristov/75686ccd3c1b41941da9b17c95d097ce to your computer and use it in GitHub Desktop.

Revisions

  1. aaristov created this gist Dec 16, 2020.
    48 changes: 48 additions & 0 deletions tea.ino
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,48 @@


    #include <Servo.h>

    Servo myservo; // create servo object to control a servo
    // twelve servo objects can be created on most boards

    int pos = 0; // variable to store the servo position
    int max_pos = 150;
    int cur_pos = 0;
    long tea_time = 180000;

    void goDown(){
    for (pos = cur_pos; pos <= max_pos; pos += 1) { // goes from 0 degrees to 180 degrees
    // in steps of 1 degree
    Serial.println(pos);
    myservo.write(pos); // tell servo to go to position in variable 'pos'
    delay(15); // waits 15ms for the servo to reach the position
    }

    cur_pos = max_pos;

    }

    void goUp(){
    if (cur_pos > 0){
    for (pos = cur_pos; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
    myservo.write(pos);
    Serial.println(pos); // tell servo to go to position in variable 'pos'
    delay(15); // waits 15ms for the servo to reach the position
    }
    }
    cur_pos = 0;
    }


    void setup() {
    Serial.begin(9600);
    myservo.attach(9); // attaches the servo on pin 9 to the servo object
    myservo.write(cur_pos);
    }

    void loop() {
    goDown();
    delay(tea_time);
    goUp();
    delay(50000000);
    }