Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
Arnov Sharma
Published © MIT

Hydrate Loop

Hydrate Loop is a smart reminder tool that ensures users never forget to drink water throughout the day.

BeginnerFull instructions provided1 hour235
Hydrate Loop

Things used in this project

Hardware components

Seeed Studio XIAO SAMD21 (Pre-Soldered) - Seeeduino XIAO
Seeed Studio XIAO SAMD21 (Pre-Soldered) - Seeeduino XIAO
×1

Software apps and online services

Fusion
Autodesk Fusion
Arduino IDE
Arduino IDE

Hand tools and fabrication machines

3D Printer (generic)
3D Printer (generic)
Seeed Studio Fusion PCB/PCBA
Seeed Studio Fusion PCB/PCBA

Story

Read more

Schematics

SCH

Code

code

C/C++
#include <Adafruit_NeoPixel.h>

// Pin connected to WS2812B LED
#define LED_PIN 0
// Number of LEDs
#define NUM_LEDS 4

Adafruit_NeoPixel strip(NUM_LEDS, LED_PIN, NEO_GRB + NEO_KHZ800);

// Timing variables
unsigned long previousMillis = 0;
const long twoHours = 7200000;         // Two hours in milliseconds
const long blinkDuration = 30000;      // 30 seconds for blinking
const long fadeInterval = 20;          // Interval for updating fade (in ms)
const long blinkInterval = 500;        // Blinking interval in ms
bool isBlinking = false;
bool isFading = true;

int fadeBrightness = 0;                // Brightness for fading
int fadeDirection = 1;                 // 1 for increasing brightness, -1 for decreasing brightness

void setup() {
    strip.begin();
    strip.show();                      // Initialize all LEDs to OFF
    setGreenFade(0);                   // Start with GREEN LED off
    previousMillis = millis();         // Start time tracking
}

void loop() {
    unsigned long currentMillis = millis();

    if (!isBlinking && (currentMillis - previousMillis >= twoHours)) {
        // Two hours passed, start blinking SKYBLUE LED
        isBlinking = true;
        isFading = false; // Stop fading during blinking
        previousMillis = currentMillis; // Reset timer for blinking duration
    }

    if (isBlinking) {
        // Blinking logic for SKYBLUE LED
        if (currentMillis - previousMillis < blinkDuration) {
            if ((currentMillis % blinkInterval) < (blinkInterval / 2)) {
                setLEDColor(strip.Color(0, 255, 255)); // SKYBLUE ON
            } else {
                setLEDColor(strip.Color(0, 0, 0));     // OFF
            }
        } else {
            // Blinking finished, reset to GREEN fading and restart the timer
            isBlinking = false;
            isFading = true;
            previousMillis = currentMillis;           // Reset timer for the next two-hour interval
        }
    }

    if (isFading) {
        // Handle fading effect for GREEN LED
        static unsigned long fadeMillis = 0;
        if (currentMillis - fadeMillis >= fadeInterval) {
            fadeMillis = currentMillis;

            fadeBrightness += fadeDirection * 5;      // Adjust brightness
            if (fadeBrightness <= 0 || fadeBrightness >= 255) {
                fadeDirection *= -1;                  // Reverse direction at min or max brightness
            }
            setGreenFade(fadeBrightness);
        }
    }
}

// Function to set a specific color for all LEDs
void setLEDColor(uint32_t color) {
    for (int i = 0; i < NUM_LEDS; i++) {
        strip.setPixelColor(i, color);
    }
    strip.show();
}

// Function to fade GREEN LED
void setGreenFade(int brightness) {
    uint32_t color = strip.Color(0, brightness, 0);  // Set green brightness
    setLEDColor(color);
}

Credits

Arnov Sharma
338 projects • 344 followers
Just your average MAKER
Contact

Comments

Please log in or sign up to comment.