FastLED 3.9.15
Loading...
Searching...
No Matches
pir.h
Go to the documentation of this file.
1#pragma once
2
3#include "fl/stl/stdint.h"
4
6#include "fl/ui/ui.h"
8
9namespace fl {
10
11// A passive infrared sensor common on amazon.
12// For best results set the PIR to maximum sensitive and minimum delay time before retrigger.
13// Instantiating this class will create a ui UIButton when
14// compiling using the FastLED web compiler.
16 public:
17 PirLowLevel(int pin);
18 bool detect();
19 operator bool() { return detect(); }
20
21 private:
22
24};
25
26// An passive infrared sensor that incorporates time to allow for latching and transitions fx. This is useful
27// for detecting motion and the increasing the brightness in response to motion.
28// Example:
29// #define PIR_LATCH_MS 15000 // how long to keep the PIR sensor active after a trigger
30// #define PIR_RISING_TIME 1000 // how long to fade in the PIR sensor
31// #define PIR_FALLING_TIME 1000 // how long to fade out the PIR sensor
32// Pir pir(PIN_PIR, PIR_LATCH_MS, PIR_RISING_TIME, PIR_FALLING_TIME);
33// void loop() {
34// uint8_t bri = pir.transition(millis());
35// FastLED.setBrightness(bri * brightness.as<float>());
36// }
37
38class Pir {
39public:
44 Pir(int pin,
45 u32 latchMs = 5000,
46 u32 risingTime = 1000,
47 u32 fallingTime = 1000,
48 const char* button_name = nullptr);
49
51 bool detect(u32 now);
52
58 u8 transition(u32 now);
59
61 void activate(u32 now) { mRamp.trigger(now); }
62
63private:
66 bool mLastState = false;
68
69};
70
71} // namespace fl
PirLowLevel mPir
Definition pir.h:64
UIButton mButton
Definition pir.h:67
void activate(u32 now)
Manually start the latch cycle (e.g. on startup)
Definition pir.h:61
bool detect(u32 now)
Returns true if the PIR is “latched on” (within latchMs of last trigger).
Definition pir.cpp.hpp:48
TimeRamp mRamp
Definition pir.h:65
bool mLastState
Definition pir.h:66
u8 transition(u32 now)
Returns a 0–255 ramp value: • ramps 0→255 over risingTime • holds 255 until latchMs–fallingTime • ram...
Definition pir.cpp.hpp:58
Pir(int pin, u32 latchMs=5000, u32 risingTime=1000, u32 fallingTime=1000, const char *button_name=nullptr)
Definition pir.cpp.hpp:40
PirLowLevel(int pin)
Definition pir.cpp.hpp:31
DigitalPin mPin
Definition pir.h:23
unsigned char u8
Definition stdint.h:131
Base definition for an LED controller.
Definition crgb.hpp:179
Aggregator header for the fl/ui/ family of per-element UI types.