Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //+++++++++++++++++++++++++++++++++++++++++++++++++++++++
- //
- // TeaTimer by DeKode (c) 2020
- // http://wiki.77f.de
- // Version 2.0
- //
- //+++++++++++++++++++++++++++++++++++++++++++++++++++++++
- //Includes:
- #include <Servo.h>
- //Declares:
- Servo liftServo;
- //Pin-Defs:
- const int pinServo = 4; //Servo-Pin
- const int pinBtnSel = 2; //Select-Button
- const int pinBtnGo = 3; //Start-Button
- const int pinLedReady = 13; //LED-Pin Ready
- const int pinLedTime[8] = {5,6,7,8,9,10,11,12}; //LED-Pins for each Minute
- //Global Variables:
- int iServoUp = 45; //Servo Up-Pos
- int iServoDown = 8; //Servo Down-Pos
- int iServoDelay = 20; //Delay for Servo movement (bigger delay = slower movement)
- int pos = 0; //actual-position
- long int iTimeSet = 60000; //Time Set to Wait (1 min) in ms
- int iBtnSel = 0, iBtnSelOld = 0; //Status Select-Button
- int iBtnGo = 0; //Status Start-Button
- int iTimeSelection = 0; //Counter for Time Selection (0=1min, 7=8min)
- void setup() {
- //PinModes:
- pinMode(pinBtnSel, INPUT_PULLUP);
- pinMode(pinBtnGo, INPUT_PULLUP);
- pinMode(pinLedReady, OUTPUT);
- for (int i = 0; i < 8; i++){
- pinMode(pinLedTime[i], OUTPUT);
- }
- fLedSwitcher(iTimeSelection); //Switch LEDs
- liftServo.attach(pinServo);
- liftServo.write(iServoUp);
- }
- void loop() {
- //Read inputs:
- iBtnSel = !digitalRead(pinBtnSel);
- iBtnGo = !digitalRead(pinBtnGo);
- //Select-Button inc Selection-Counter till max-val then resets to 0:
- if(iBtnSel != iBtnSelOld){
- if(iBtnSel == 1){
- if(iTimeSelection < 7){
- iTimeSelection++;
- }else{
- iTimeSelection = 0;
- }
- fLedSwitcher(iTimeSelection); //Switch LEDs back to selected Time
- }
- delay(100);
- iBtnSelOld = iBtnSel;
- }
- //Start-Button: Servo Down, Wait Selected Time, Servo Up
- if(iBtnGo){
- digitalWrite(pinLedReady, LOW); //Ready-LED reset
- fServoDown();
- for(int i = 0; i <= iTimeSelection ;i++){ //Cycle 1 min for x times
- int iCounter = (i-iTimeSelection)*(-1); //Reverse Counter
- fLedSwitcher(iCounter); //Switch LEDs with cycle-number
- delay(iTimeSet); //Wait for 1 min
- }
- fServoUp();
- }
- digitalWrite(pinLedReady, HIGH); //Ready-LED if Timer finished
- }
- //Function to drive the Servo down
- void fServoDown(){
- //Servo in Start-Pos (for double-check)
- liftServo.write(iServoUp);
- //Slowly move Servo
- for(pos = iServoUp; pos >= iServoDown; pos--){
- liftServo.write(pos);
- delay(iServoDelay);
- }
- //Servo in End-Pos
- liftServo.write(iServoDown);
- }
- void fServoUp(){
- //Servo in Start-Pos (for double-check)
- liftServo.write(iServoDown);
- //Slowly move Servo
- for(pos = iServoDown; pos <= iServoUp; pos++){
- liftServo.write(pos);
- delay(iServoDelay);
- }
- //Servo in End-Pos
- liftServo.write(iServoUp);
- }
- //Function LED-Switcher
- void fLedSwitcher(int iTimeSetting){
- //Turn all LED off:
- for (int i = 0; i<8; i++){
- digitalWrite(pinLedTime[i], LOW);
- }
- //Turn LED for iTimeSetting on:
- digitalWrite(pinLedTime[iTimeSetting], HIGH);
- }
Add Comment
Please, Sign In to add comment