1#define FASTLED_INTERNAL
4#include "sensors/pir.h"
14 int count = g_counter++;
18 return Str(
"Pir ").append(g_counter++);
23Pir::Pir(
int pin): mButton(buttonName().c_str()), mPin(pin) {
24 mPin.setPinMode(DigitalPin::kInput);
28 return mPin.high() || mButton.clicked();
31PirAdvanced::PirAdvanced(
int pin, uint32_t latchMs, uint32_t risingTime, uint32_t fallingTime)
34 , mRisingTime(risingTime)
35 , mFallingTime(fallingTime)
39 if (mRisingTime + mFallingTime > mLatchMs) {
40 FASTLED_WARN(
"PirAdvanced: risingTime + fallingTime must be less than latchMs");
41 mRisingTime = mLatchMs / 2;
42 mFallingTime = mLatchMs / 2;
46bool PirAdvanced::detect(uint32_t now) {
47 bool currentState = mPir.detect();
49 if (currentState && !mLastState) {
53 mLastState = currentState;
54 return (now - mLastTrigger) < mLatchMs;
57uint8_t PirAdvanced::transition(uint32_t now) {
59 uint32_t elapsed = now - mLastTrigger;
62 if (elapsed < mRisingTime) {
64 out = MAX(mLastTransition, (elapsed * 255) / mRisingTime);
66 else if (elapsed >= mLatchMs - mFallingTime && elapsed < mLatchMs) {
68 uint32_t fallingElapsed = elapsed - (mLatchMs - mFallingTime);
69 out = 255 - ((fallingElapsed * 255) / mFallingTime);
71 else if (elapsed >= mRisingTime && elapsed < mLatchMs - mFallingTime) {
75 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.