mirror of
https://github.com/zzzzDev4/IAS-Better-Tea.git
synced 2025-04-21 07:31:20 +02:00
Added SmartButtons for +- 10s config
This commit is contained in:
parent
1a69a5b202
commit
b4e402c601
5 changed files with 76 additions and 13 deletions
|
@ -16,3 +16,4 @@ lib_deps =
|
|||
adafruit/Adafruit SSD1306@^2.5.9
|
||||
arduino-libraries/Arduino_JSON@^0.2.0
|
||||
adafruit/Adafruit PN532@^1.3.3
|
||||
fastled/FastLED@^3.6.0
|
||||
|
|
27
src/SmartButton.cpp
Normal file
27
src/SmartButton.cpp
Normal file
|
@ -0,0 +1,27 @@
|
|||
#include "SmartButton.hpp"
|
||||
#include <Arduino.h>
|
||||
|
||||
SmartButton::SmartButton(int pin)
|
||||
{
|
||||
m_pin = pin;
|
||||
}
|
||||
|
||||
void SmartButton::init()
|
||||
{
|
||||
pinMode(m_pin, INPUT);
|
||||
}
|
||||
|
||||
bool SmartButton::isJustPressed()
|
||||
{
|
||||
if (digitalRead(m_pin) == HIGH)
|
||||
{
|
||||
m_isDown = false;
|
||||
return false;
|
||||
}
|
||||
if (digitalRead(m_pin) == LOW && !m_isDown)
|
||||
{
|
||||
m_isDown = true;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
11
src/SmartButton.hpp
Normal file
11
src/SmartButton.hpp
Normal file
|
@ -0,0 +1,11 @@
|
|||
#pragma once
|
||||
|
||||
class SmartButton {
|
||||
public:
|
||||
SmartButton(int pin);
|
||||
void init();
|
||||
bool isJustPressed();
|
||||
private:
|
||||
bool m_isDown;
|
||||
int m_pin;
|
||||
};
|
47
src/main.cpp
47
src/main.cpp
|
@ -1,12 +1,14 @@
|
|||
#include "main.hpp"
|
||||
#include "secrets.hpp"
|
||||
#include "song.h"
|
||||
#include <FastLED.h>
|
||||
|
||||
#define WIRE Wire
|
||||
|
||||
#define SERVO_PIN 14 // D5
|
||||
#define POTENTIOMETER_PIN A0 // A0
|
||||
#define BUZZER_PIN 12 // D6
|
||||
#define LEDSTRIPE_PIN 15 // D8
|
||||
|
||||
// buttons
|
||||
#define TACTILE_BTN_LEFT 0 // D3
|
||||
|
@ -22,6 +24,10 @@ Adafruit_PN532 nfc(PN532_IRQ, PN532_RESET); // RFID with I2C
|
|||
#define DISPLAY_PIN 4 // D2 (SDA)
|
||||
auto display = Adafruit_SSD1306(128, 32, &WIRE);
|
||||
|
||||
// FastLED
|
||||
#define PIXELCOUNT 20
|
||||
CRGB leds[PIXELCOUNT]; // Define the array of leds
|
||||
|
||||
// util classes
|
||||
ContinuousServo contServo(SERVO_PIN);
|
||||
TeaTimer teaTimer(&contServo);
|
||||
|
@ -30,6 +36,9 @@ SmartDial smartDial(POTENTIOMETER_PIN);
|
|||
SmartDisplay smartDisplay(&display);
|
||||
TeaNetworking teaNet;
|
||||
|
||||
SmartButton buttonLeft(TACTILE_BTN_LEFT);
|
||||
SmartButton buttonRight(TACTILE_BTN_RIGHT);
|
||||
|
||||
// networking
|
||||
String shuttleServer = "https://ias-tea-axum.shuttleapp.rs";
|
||||
|
||||
|
@ -49,6 +58,24 @@ void setup()
|
|||
{
|
||||
Serial.begin(9600);
|
||||
|
||||
// FastLED setup
|
||||
FastLED.addLeds<WS2812B, LEDSTRIPE_PIN, RGB>(leds, PIXELCOUNT);
|
||||
FastLED.clear(true);
|
||||
FastLED.show();
|
||||
delay(2000);
|
||||
|
||||
leds[0].setRGB(2, 0, 0);
|
||||
FastLED.show();
|
||||
delay(1000);
|
||||
|
||||
leds[10].setRGB(0, 2, 0);
|
||||
FastLED.show();
|
||||
delay(1000);
|
||||
|
||||
leds[19].setRGB(0, 0, 2);
|
||||
FastLED.show();
|
||||
delay(1000);
|
||||
|
||||
teaNet.init(ssid, password);
|
||||
|
||||
smartRFID.init();
|
||||
|
@ -62,11 +89,10 @@ void setup()
|
|||
pinMode(LED_BUILTIN, OUTPUT);
|
||||
pinMode(TOUCH_BTN_PIN, INPUT);
|
||||
|
||||
pinMode(TACTILE_BTN_LEFT, INPUT);
|
||||
pinMode(TACTILE_BTN_RIGHT, INPUT);
|
||||
buttonLeft.init();
|
||||
buttonRight.init();
|
||||
}
|
||||
|
||||
int steepingSeconds = 60;
|
||||
void loop()
|
||||
{
|
||||
|
||||
|
@ -96,7 +122,7 @@ void loop()
|
|||
{
|
||||
smartDisplay.printWaitForRFIDScreen();
|
||||
|
||||
playSong();
|
||||
// playSong();
|
||||
|
||||
// this blocks execution until a tag has been detected
|
||||
String uid = smartRFID.readTag();
|
||||
|
@ -121,7 +147,7 @@ void loop()
|
|||
result = teaNet.httpsGETRequest(shuttleServer + "/teabyrfid/" + uid);
|
||||
}
|
||||
|
||||
currentTea = TeaData(result["teaname"], result["rfidcode"], result["watertemp"], result["steepingSeconds"]);
|
||||
currentTea = TeaData(result["teaname"], result["rfidcode"], result["watertemp"], result["steepingseconds"]);
|
||||
|
||||
state = State::DISPLAY_SCANNED_TEA_CONFIG;
|
||||
|
||||
|
@ -131,18 +157,15 @@ void loop()
|
|||
{
|
||||
int dir = smartDial.smoothEdit(¤tTea.m_steepingSeconds, 0, 6000);
|
||||
|
||||
if (digitalRead(TACTILE_BTN_LEFT) == LOW)
|
||||
if (buttonLeft.isJustPressed())
|
||||
{
|
||||
printMsg("BUTTON GREEN");
|
||||
currentTea.m_steepingSeconds -= 10;
|
||||
}
|
||||
else if (digitalRead(TACTILE_BTN_RIGHT) == LOW)
|
||||
if (buttonRight.isJustPressed())
|
||||
{
|
||||
printMsg("BUTTON RED");
|
||||
currentTea.m_steepingSeconds += 10;
|
||||
}
|
||||
else
|
||||
{
|
||||
smartDisplay.printTeaConfigScreen(currentTea.m_teaName, currentTea.m_steepingSeconds, dir);
|
||||
}
|
||||
|
||||
// change state if start pressed
|
||||
if (isBtnPressed())
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include "SmartDisplay.hpp"
|
||||
#include "TeaNetworking.hpp"
|
||||
#include "TeaData.hpp"
|
||||
#include "SmartButton.hpp"
|
||||
|
||||
void playSong();
|
||||
bool toggle_led(void *);
|
||||
|
|
Loading…
Add table
Reference in a new issue