diff --git a/src/ContinuousServo.cpp b/src/ContinuousServo.cpp index efacbdb..8522bea 100644 --- a/src/ContinuousServo.cpp +++ b/src/ContinuousServo.cpp @@ -14,7 +14,7 @@ void ContinuousServo::moveServoForMillisClockwise(unsigned long duration) { return; } - myservo.write(NEUTRAL_POS + 50); + myservo.write(NEUTRAL_POS + speed); m_endTurningTime = millis() + duration; m_isTurning = true; } @@ -24,7 +24,7 @@ void ContinuousServo::moveServoForMillisCounterClockwise(unsigned long duration) { return; } - myservo.write(NEUTRAL_POS - 50); + myservo.write(NEUTRAL_POS - speed); m_endTurningTime = millis() + duration; m_isTurning = true; } diff --git a/src/ContinuousServo.hpp b/src/ContinuousServo.hpp index 6efaa02..2d06588 100644 --- a/src/ContinuousServo.hpp +++ b/src/ContinuousServo.hpp @@ -15,4 +15,5 @@ private: bool m_isTurning = false; unsigned long m_endTurningTime; const int NEUTRAL_POS = 88; + const int speed = 10; }; diff --git a/src/SmartServo.cpp b/src/SmartServo.cpp index 4c27a10..ccf3b13 100644 --- a/src/SmartServo.cpp +++ b/src/SmartServo.cpp @@ -2,7 +2,7 @@ SmartServo::SmartServo(int pin) { - myservo.attach(pin); + myservo.attach(pin, 650, 2600); } // Note: This blocks execution until servo finished moving. diff --git a/src/SmartServo.hpp b/src/SmartServo.hpp index 3cb45dd..2da77a2 100644 --- a/src/SmartServo.hpp +++ b/src/SmartServo.hpp @@ -9,7 +9,7 @@ public: void moveServoToZero(); void moveServoTo180(); -private: Servo myservo; +private: bool toggle = false; }; diff --git a/src/TeaTimer.cpp b/src/TeaTimer.cpp index 72a0ea6..7a9a6db 100644 --- a/src/TeaTimer.cpp +++ b/src/TeaTimer.cpp @@ -10,13 +10,13 @@ void TeaTimer::beginSteeping(unsigned long t_steepingDuration) { if (m_isSteeping) return; - m_servo->moveServoTo180(); //moveServoForMillisClockwise(m_servoTurningTime); + m_servo->moveServoTo(105, 2); m_endSteepingTime = millis() + t_steepingDuration; m_isSteeping = true; } // Move servo up, stop timer immediately. -void TeaTimer::end_steeping() +void TeaTimer::endSteeping() { m_servo->moveServoToZero(); m_isSteeping = false; @@ -27,7 +27,7 @@ void TeaTimer::tick() { if (millis() >= m_endSteepingTime && m_isSteeping) { - end_steeping(); + endSteeping(); } } diff --git a/src/TeaTimer.hpp b/src/TeaTimer.hpp index eb570e6..d0a8c79 100644 --- a/src/TeaTimer.hpp +++ b/src/TeaTimer.hpp @@ -1,8 +1,7 @@ #pragma once #include #include "SmartServo.hpp" -//#include "ContinuousServo.hpp" -#include "SmartServo.hpp" +#include "ContinuousServo.hpp" class TeaTimer { @@ -11,7 +10,7 @@ public: // Move servo down, start timer. void beginSteeping(unsigned long t_steepingDuration); // Move servo up, stop timer immediately. - void end_steeping(); + void endSteeping(); // Called at start of update. void tick(); unsigned long remainingSteepTimeSeconds(); @@ -21,6 +20,6 @@ private: bool m_isSteeping = false; // The time in millis when steeping is done. unsigned long m_endSteepingTime; - unsigned long m_servoTurningTime = 250; + unsigned long m_servoTurningTime = 1000; SmartServo *m_servo; }; \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 7d12720..3dd3efa 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -30,6 +30,7 @@ CRGB leds[PIXELCOUNT]; // Define the array of leds // util classes // ContinuousServo contServo(SERVO_PIN); +// SmartContServo smartServo(SERVO_PIN); SmartServo smartServo(SERVO_PIN); TeaTimer teaTimer(&smartServo); SmartRFID smartRFID(&nfc); @@ -61,6 +62,7 @@ enum State // debugging states NETWORKING_DEBUG, + SERVO_TUNING, }; State state = State::WAIT_FOR_RFID_SCAN; @@ -68,6 +70,8 @@ void setup() { Serial.begin(9600); + smartServo.moveServoToZero(); + // FastLED setup FastLED.addLeds(leds, PIXELCOUNT); FastLED.clear(true); @@ -105,16 +109,25 @@ void setup() buttonLeft.init(); buttonRight.init(); - - smartServo.moveServoToZero(); } void loop() { - // contServo.tick(); switch (state) { + case SERVO_TUNING: + { + // default min 1000, max 2000 + smartDisplay.printMsg("Write servo 0"); + smartServo.myservo.write(0); + delay(2000); + + smartDisplay.printMsg("Write servo 180"); + smartServo.myservo.write(180); + delay(2000); + break; + } case NETWORKING_DEBUG: { if (!teaNet.wifiConnected()) @@ -235,7 +248,7 @@ void loop() delay(1000); break; } - teaTimer.beginSteeping(5000); + teaTimer.beginSteeping(currentTea.m_steepingSeconds * 1000); state = State::STEEPING_IN_PROGRESS; } break; @@ -245,6 +258,16 @@ void loop() teaTimer.tick(); if (teaTimer.isSteeping()) { + // abort if red button pressed + if (buttonLeft.isJustPressed()) + { + teaTimer.endSteeping(); + smartDisplay.printMsg("DONE"); + delay(1000); + state = State::REQUEST_FEEDBACK; + break; + } + auto r = teaTimer.remainingSteepTimeSeconds(); smartDisplay.printTeaSteepingProgressScreen(currentTea, r); }