diff --git a/src/Controls.cpp b/src/Controls.cpp new file mode 100644 index 0000000..fa0cb67 --- /dev/null +++ b/src/Controls.cpp @@ -0,0 +1,33 @@ +#include "Controls.h" + + +uint8_t controlPins[] = { + PIN_A, + PIN_B, + PIN_KEY, +}; + + +void Controls_setup(){ + pinMode(PIN_A, INPUT_PULLDOWN); + pinMode(PIN_B, INPUT_PULLDOWN); + pinMode(PIN_KEY, INPUT_PULLDOWN); +} + +int16_t prevState[3]; + +void Controls_loop(){ + for(uint8_t a=0; a%d\n", pin, prevValue, currentValue); + + if(abs(currentValue - prevValue) > 100){ + Serial.println("Changed!"); + } + + prevState[a] = currentValue; + } +} \ No newline at end of file diff --git a/src/Controls.h b/src/Controls.h new file mode 100644 index 0000000..edaf7e4 --- /dev/null +++ b/src/Controls.h @@ -0,0 +1,11 @@ +#pragma once + +#include + +#define PIN_A 2 +#define PIN_B 3 +#define PIN_KEY 4 + + +void Controls_setup(); +void Controls_loop(); \ No newline at end of file diff --git a/src/Hanglamp.cpp b/src/Hanglamp.cpp index bef32c8..6388c63 100644 --- a/src/Hanglamp.cpp +++ b/src/Hanglamp.cpp @@ -9,10 +9,12 @@ #define _TASK_STATUS_REQUEST // Compile with support for StatusRequest functionality - triggering tasks on status change events in addition to time only // #define ENABLE_MQTT -#define ENABLE_WIFI +// #define ENABLE_WIFI // #define ENABLE_FS // #define ENABLE_PINFINDER #define ENABLE_COLORS +// #define ENABLE_PIN_SENSING +#define ENABLE_CONTROLS // #include @@ -33,6 +35,10 @@ #include "PinFinder.h" #endif +#ifdef ENABLE_CONTROLS +#include "Controls.h" +#endif + #ifdef ENABLE_COLORS CRGB colorTable[] = { @@ -88,22 +94,57 @@ CRGB colorTable[] = { }; uint8_t colorIndex = 0; -void colors(){ - colorIndex++; - if(colorIndex >= (sizeof(colorTable) / sizeof(CRGB))){ - colorIndex = 0; +void colors(void *pvParameters){ + while(true){ + colorIndex++; + if(colorIndex >= (sizeof(colorTable) / sizeof(CRGB))){ + colorIndex = 0; + } + Serial.printf("colorIndex: %d\n", colorIndex); + jumpTo(colorTable[colorIndex]); + + vTaskDelay(1000 / portTICK_PERIOD_MS); } - Serial.printf("colorIndex: %d\n", colorIndex); - jumpTo(colorTable[colorIndex]); + + vTaskDelete(NULL); } #endif +#ifdef ENABLE_PIN_SENSING +gpio_num_t sensePins[] = { + (gpio_num_t) 0, + (gpio_num_t) 1, + (gpio_num_t) 2, + (gpio_num_t) 3, + (gpio_num_t) 4, + (gpio_num_t) 5, + (gpio_num_t) 6, + (gpio_num_t) 7, + (gpio_num_t) 8, + (gpio_num_t) 9, + (gpio_num_t) 10, + (gpio_num_t) 20, + (gpio_num_t) 21, +}; + +long prevStates[sizeof(sensePins)]; +#endif + void setup() { Serial.begin(115200); - delay(500); + delay(1500); + + #ifdef ENABLE_PIN_SENSING + for(int i=0; i 10){ + Serial.printf("pin#%02d %d->%d\n", pin, prevStates[i], currentState); + // } + prevStates[i] = currentState; + } + + + for(int i=0; i #endif -#define PIN_STRIP1 3 -#define PIN_STRIP2 4 +#define PIN_STRIP1 5 +#define PIN_STRIP2 6 #define STRIP_LENGTH 46