1#define FASTLED_INTERNAL
4#include "sensors/pir.h"
5#include "fl/strstream.h"
14 Str getButtonName(
const char* button_name) {
16 return Str(button_name);
18 int count = g_counter++;
23 s <<
"Pir " << g_counter++;
29Pir::Pir(
int pin,
const char* button_name): mButton(getButtonName(button_name).c_str()), mPin(pin) {
30 mPin.setPinMode(DigitalPin::kInput);
34 return mPin.high() || mButton.clicked();
37PirAdvanced::PirAdvanced(
int pin, uint32_t latchMs, uint32_t risingTime, uint32_t fallingTime)
40 , mRisingTime(risingTime)
41 , mFallingTime(fallingTime)
45 if (mRisingTime + mFallingTime > mLatchMs) {
46 FASTLED_WARN(
"PirAdvanced: risingTime + fallingTime must be less than latchMs");
47 mRisingTime = mLatchMs / 2;
48 mFallingTime = mLatchMs / 2;
52bool PirAdvanced::detect(uint32_t now) {
53 bool currentState = mPir.detect();
55 if (currentState && !mLastState) {
59 mLastState = currentState;
60 return (now - mLastTrigger) < mLatchMs;
63uint8_t PirAdvanced::transition(uint32_t now) {
65 uint32_t elapsed = now - mLastTrigger;
68 if (elapsed < mRisingTime) {
70 out = MAX(mLastTransition, (elapsed * 255) / mRisingTime);
72 else if (elapsed >= mLatchMs - mFallingTime && elapsed < mLatchMs) {
74 uint32_t fallingElapsed = elapsed - (mLatchMs - mFallingTime);
75 out = 255 - ((fallingElapsed * 255) / mFallingTime);
77 else if (elapsed >= mRisingTime && elapsed < mLatchMs - mFallingTime) {
81 mLastTransition = out;
central include file for FastLED, defines the CFastLED class/object
Class base definitions for defining fast pin access.
Implements a simple red square effect for 2D LED grids.