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