4
0
Fork 0
mirror of https://github.com/zzzzDev4/IAS-Better-Tea.git synced 2025-04-21 07:31:20 +02:00

Normal servo calibrated and lifecycle improvements

This commit is contained in:
zzzz 2024-05-20 20:23:55 +02:00
parent 12b1fb9d00
commit d21406ce06
7 changed files with 38 additions and 15 deletions

View file

@ -14,7 +14,7 @@ void ContinuousServo::moveServoForMillisClockwise(unsigned long duration)
{ {
return; return;
} }
myservo.write(NEUTRAL_POS + 50); myservo.write(NEUTRAL_POS + speed);
m_endTurningTime = millis() + duration; m_endTurningTime = millis() + duration;
m_isTurning = true; m_isTurning = true;
} }
@ -24,7 +24,7 @@ void ContinuousServo::moveServoForMillisCounterClockwise(unsigned long duration)
{ {
return; return;
} }
myservo.write(NEUTRAL_POS - 50); myservo.write(NEUTRAL_POS - speed);
m_endTurningTime = millis() + duration; m_endTurningTime = millis() + duration;
m_isTurning = true; m_isTurning = true;
} }

View file

@ -15,4 +15,5 @@ private:
bool m_isTurning = false; bool m_isTurning = false;
unsigned long m_endTurningTime; unsigned long m_endTurningTime;
const int NEUTRAL_POS = 88; const int NEUTRAL_POS = 88;
const int speed = 10;
}; };

View file

@ -2,7 +2,7 @@
SmartServo::SmartServo(int pin) SmartServo::SmartServo(int pin)
{ {
myservo.attach(pin); myservo.attach(pin, 650, 2600);
} }
// Note: This blocks execution until servo finished moving. // Note: This blocks execution until servo finished moving.

View file

@ -9,7 +9,7 @@ public:
void moveServoToZero(); void moveServoToZero();
void moveServoTo180(); void moveServoTo180();
private:
Servo myservo; Servo myservo;
private:
bool toggle = false; bool toggle = false;
}; };

View file

@ -10,13 +10,13 @@ void TeaTimer::beginSteeping(unsigned long t_steepingDuration)
{ {
if (m_isSteeping) if (m_isSteeping)
return; return;
m_servo->moveServoTo180(); //moveServoForMillisClockwise(m_servoTurningTime); m_servo->moveServoTo(105, 2);
m_endSteepingTime = millis() + t_steepingDuration; m_endSteepingTime = millis() + t_steepingDuration;
m_isSteeping = true; m_isSteeping = true;
} }
// Move servo up, stop timer immediately. // Move servo up, stop timer immediately.
void TeaTimer::end_steeping() void TeaTimer::endSteeping()
{ {
m_servo->moveServoToZero(); m_servo->moveServoToZero();
m_isSteeping = false; m_isSteeping = false;
@ -27,7 +27,7 @@ void TeaTimer::tick()
{ {
if (millis() >= m_endSteepingTime && m_isSteeping) if (millis() >= m_endSteepingTime && m_isSteeping)
{ {
end_steeping(); endSteeping();
} }
} }

View file

@ -1,8 +1,7 @@
#pragma once #pragma once
#include <Arduino.h> #include <Arduino.h>
#include "SmartServo.hpp" #include "SmartServo.hpp"
//#include "ContinuousServo.hpp" #include "ContinuousServo.hpp"
#include "SmartServo.hpp"
class TeaTimer class TeaTimer
{ {
@ -11,7 +10,7 @@ public:
// Move servo down, start timer. // Move servo down, start timer.
void beginSteeping(unsigned long t_steepingDuration); void beginSteeping(unsigned long t_steepingDuration);
// Move servo up, stop timer immediately. // Move servo up, stop timer immediately.
void end_steeping(); void endSteeping();
// Called at start of update. // Called at start of update.
void tick(); void tick();
unsigned long remainingSteepTimeSeconds(); unsigned long remainingSteepTimeSeconds();
@ -21,6 +20,6 @@ private:
bool m_isSteeping = false; bool m_isSteeping = false;
// The time in millis when steeping is done. // The time in millis when steeping is done.
unsigned long m_endSteepingTime; unsigned long m_endSteepingTime;
unsigned long m_servoTurningTime = 250; unsigned long m_servoTurningTime = 1000;
SmartServo *m_servo; SmartServo *m_servo;
}; };

View file

@ -30,6 +30,7 @@ CRGB leds[PIXELCOUNT]; // Define the array of leds
// util classes // util classes
// ContinuousServo contServo(SERVO_PIN); // ContinuousServo contServo(SERVO_PIN);
// SmartContServo smartServo(SERVO_PIN);
SmartServo smartServo(SERVO_PIN); SmartServo smartServo(SERVO_PIN);
TeaTimer teaTimer(&smartServo); TeaTimer teaTimer(&smartServo);
SmartRFID smartRFID(&nfc); SmartRFID smartRFID(&nfc);
@ -61,6 +62,7 @@ enum State
// debugging states // debugging states
NETWORKING_DEBUG, NETWORKING_DEBUG,
SERVO_TUNING,
}; };
State state = State::WAIT_FOR_RFID_SCAN; State state = State::WAIT_FOR_RFID_SCAN;
@ -68,6 +70,8 @@ void setup()
{ {
Serial.begin(9600); Serial.begin(9600);
smartServo.moveServoToZero();
// FastLED setup // FastLED setup
FastLED.addLeds<WS2812B, LEDSTRIPE_PIN, RGB>(leds, PIXELCOUNT); FastLED.addLeds<WS2812B, LEDSTRIPE_PIN, RGB>(leds, PIXELCOUNT);
FastLED.clear(true); FastLED.clear(true);
@ -105,16 +109,25 @@ void setup()
buttonLeft.init(); buttonLeft.init();
buttonRight.init(); buttonRight.init();
smartServo.moveServoToZero();
} }
void loop() void loop()
{ {
// contServo.tick();
switch (state) 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: case NETWORKING_DEBUG:
{ {
if (!teaNet.wifiConnected()) if (!teaNet.wifiConnected())
@ -235,7 +248,7 @@ void loop()
delay(1000); delay(1000);
break; break;
} }
teaTimer.beginSteeping(5000); teaTimer.beginSteeping(currentTea.m_steepingSeconds * 1000);
state = State::STEEPING_IN_PROGRESS; state = State::STEEPING_IN_PROGRESS;
} }
break; break;
@ -245,6 +258,16 @@ void loop()
teaTimer.tick(); teaTimer.tick();
if (teaTimer.isSteeping()) 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(); auto r = teaTimer.remainingSteepTimeSeconds();
smartDisplay.printTeaSteepingProgressScreen(currentTea, r); smartDisplay.printTeaSteepingProgressScreen(currentTea, r);
} }