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
|
adafruit/Adafruit SSD1306@^2.5.9
|
||||||
arduino-libraries/Arduino_JSON@^0.2.0
|
arduino-libraries/Arduino_JSON@^0.2.0
|
||||||
adafruit/Adafruit PN532@^1.3.3
|
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 "main.hpp"
|
||||||
#include "secrets.hpp"
|
#include "secrets.hpp"
|
||||||
#include "song.h"
|
#include "song.h"
|
||||||
|
#include <FastLED.h>
|
||||||
|
|
||||||
#define WIRE Wire
|
#define WIRE Wire
|
||||||
|
|
||||||
#define SERVO_PIN 14 // D5
|
#define SERVO_PIN 14 // D5
|
||||||
#define POTENTIOMETER_PIN A0 // A0
|
#define POTENTIOMETER_PIN A0 // A0
|
||||||
#define BUZZER_PIN 12 // D6
|
#define BUZZER_PIN 12 // D6
|
||||||
|
#define LEDSTRIPE_PIN 15 // D8
|
||||||
|
|
||||||
// buttons
|
// buttons
|
||||||
#define TACTILE_BTN_LEFT 0 // D3
|
#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)
|
#define DISPLAY_PIN 4 // D2 (SDA)
|
||||||
auto display = Adafruit_SSD1306(128, 32, &WIRE);
|
auto display = Adafruit_SSD1306(128, 32, &WIRE);
|
||||||
|
|
||||||
|
// FastLED
|
||||||
|
#define PIXELCOUNT 20
|
||||||
|
CRGB leds[PIXELCOUNT]; // Define the array of leds
|
||||||
|
|
||||||
// util classes
|
// util classes
|
||||||
ContinuousServo contServo(SERVO_PIN);
|
ContinuousServo contServo(SERVO_PIN);
|
||||||
TeaTimer teaTimer(&contServo);
|
TeaTimer teaTimer(&contServo);
|
||||||
|
@ -30,6 +36,9 @@ SmartDial smartDial(POTENTIOMETER_PIN);
|
||||||
SmartDisplay smartDisplay(&display);
|
SmartDisplay smartDisplay(&display);
|
||||||
TeaNetworking teaNet;
|
TeaNetworking teaNet;
|
||||||
|
|
||||||
|
SmartButton buttonLeft(TACTILE_BTN_LEFT);
|
||||||
|
SmartButton buttonRight(TACTILE_BTN_RIGHT);
|
||||||
|
|
||||||
// networking
|
// networking
|
||||||
String shuttleServer = "https://ias-tea-axum.shuttleapp.rs";
|
String shuttleServer = "https://ias-tea-axum.shuttleapp.rs";
|
||||||
|
|
||||||
|
@ -49,6 +58,24 @@ void setup()
|
||||||
{
|
{
|
||||||
Serial.begin(9600);
|
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);
|
teaNet.init(ssid, password);
|
||||||
|
|
||||||
smartRFID.init();
|
smartRFID.init();
|
||||||
|
@ -62,11 +89,10 @@ void setup()
|
||||||
pinMode(LED_BUILTIN, OUTPUT);
|
pinMode(LED_BUILTIN, OUTPUT);
|
||||||
pinMode(TOUCH_BTN_PIN, INPUT);
|
pinMode(TOUCH_BTN_PIN, INPUT);
|
||||||
|
|
||||||
pinMode(TACTILE_BTN_LEFT, INPUT);
|
buttonLeft.init();
|
||||||
pinMode(TACTILE_BTN_RIGHT, INPUT);
|
buttonRight.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
int steepingSeconds = 60;
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -96,7 +122,7 @@ void loop()
|
||||||
{
|
{
|
||||||
smartDisplay.printWaitForRFIDScreen();
|
smartDisplay.printWaitForRFIDScreen();
|
||||||
|
|
||||||
playSong();
|
// playSong();
|
||||||
|
|
||||||
// this blocks execution until a tag has been detected
|
// this blocks execution until a tag has been detected
|
||||||
String uid = smartRFID.readTag();
|
String uid = smartRFID.readTag();
|
||||||
|
@ -121,7 +147,7 @@ void loop()
|
||||||
result = teaNet.httpsGETRequest(shuttleServer + "/teabyrfid/" + uid);
|
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;
|
state = State::DISPLAY_SCANNED_TEA_CONFIG;
|
||||||
|
|
||||||
|
@ -131,18 +157,15 @@ void loop()
|
||||||
{
|
{
|
||||||
int dir = smartDial.smoothEdit(¤tTea.m_steepingSeconds, 0, 6000);
|
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);
|
smartDisplay.printTeaConfigScreen(currentTea.m_teaName, currentTea.m_steepingSeconds, dir);
|
||||||
}
|
|
||||||
|
|
||||||
// change state if start pressed
|
// change state if start pressed
|
||||||
if (isBtnPressed())
|
if (isBtnPressed())
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
#include "SmartDisplay.hpp"
|
#include "SmartDisplay.hpp"
|
||||||
#include "TeaNetworking.hpp"
|
#include "TeaNetworking.hpp"
|
||||||
#include "TeaData.hpp"
|
#include "TeaData.hpp"
|
||||||
|
#include "SmartButton.hpp"
|
||||||
|
|
||||||
void playSong();
|
void playSong();
|
||||||
bool toggle_led(void *);
|
bool toggle_led(void *);
|
||||||
|
|
Loading…
Add table
Reference in a new issue