diff --git a/src/SmartStrip.cpp b/src/SmartStrip.cpp new file mode 100644 index 0000000..ddce152 --- /dev/null +++ b/src/SmartStrip.cpp @@ -0,0 +1,29 @@ +#include "SmartStrip.hpp" + +#define LEDSTRIPE_PIN 15 // D8 + +void SmartStrip::init() +{ + FastLED.addLeds(leds, 15); + reset(); +} + +void SmartStrip::reset() +{ + FastLED.clear(true); + FastLED.show(); +} + +void SmartStrip::setGreen(int led) +{ + leds[led].setRGB(0, 2, 0); + FastLED.show(); +} + +void SmartStrip::progressBar(int min, int max, int val) +{ + // starts at 14 and goes down to 0 as steeping continues + int level = map(val, min, max, 0, 14); + + // TODO: only update strip when necessarry +} \ No newline at end of file diff --git a/src/SmartStrip.hpp b/src/SmartStrip.hpp new file mode 100644 index 0000000..4fd68e2 --- /dev/null +++ b/src/SmartStrip.hpp @@ -0,0 +1,21 @@ +#pragma once +#include + +#define PIXELCOUNT 15 + + +class SmartStrip +{ +public: + + void init(); + + void reset(); + + void setGreen(int led); + + void progressBar(int min, int max, int val); + +private: + CRGB leds[PIXELCOUNT]; // Define the array of leds +}; \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 3dd3efa..42f3cb4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,13 +1,11 @@ #include "main.hpp" #include "secrets.hpp" -#include #define WIRE Wire -#define SERVO_PIN 14 // D5 -#define POTENTIOMETER_PIN A0 // A0 -#define BUZZER_PIN 12 // D6 -#define LEDSTRIPE_PIN 15 // D8 +#define SERVO_PIN 14 // D5 +#define BUZZER_PIN 12 // D6 +#define LEDSTRIPE_PIN 15 // D8 // buttons #define TACTILE_BTN_LEFT 0 // D3 @@ -24,17 +22,11 @@ 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 15 -CRGB leds[PIXELCOUNT]; // Define the array of leds - // util classes -// ContinuousServo contServo(SERVO_PIN); -// SmartContServo smartServo(SERVO_PIN); +SmartStrip smartStrip; SmartServo smartServo(SERVO_PIN); TeaTimer teaTimer(&smartServo); SmartRFID smartRFID(&nfc); -SmartDial smartDial(POTENTIOMETER_PIN); SmartDisplay smartDisplay(&display); TeaNetworking teaNet; @@ -72,23 +64,11 @@ void setup() smartServo.moveServoToZero(); - // FastLED setup - FastLED.addLeds(leds, PIXELCOUNT); - FastLED.clear(true); - FastLED.show(); - delay(500); + smartStrip.init(); - leds[0].setRGB(2, 0, 0); - FastLED.show(); - delay(500); - - leds[10].setRGB(0, 2, 0); - FastLED.show(); - delay(500); - - leds[14].setRGB(0, 0, 2); - FastLED.show(); - delay(500); + smartStrip.setGreen(0); + smartStrip.setGreen(7); + smartStrip.setGreen(14); smartRFID.init(); @@ -250,6 +230,7 @@ void loop() } teaTimer.beginSteeping(currentTea.m_steepingSeconds * 1000); state = State::STEEPING_IN_PROGRESS; + smartStrip.reset(); } break; } @@ -270,6 +251,9 @@ void loop() auto r = teaTimer.remainingSteepTimeSeconds(); smartDisplay.printTeaSteepingProgressScreen(currentTea, r); + + // update led strip + smartStrip.progressBar(0, currentTea.m_steepingSeconds, r); } else { diff --git a/src/main.hpp b/src/main.hpp index d458c84..668673c 100644 --- a/src/main.hpp +++ b/src/main.hpp @@ -9,6 +9,7 @@ #include #include +#include "SmartStrip.hpp" #include "TeaTimer.hpp" #include "SmartRFID.hpp" #include "ContinuousServo.hpp"