From 1fc90511ac0eb78892d013566c854c9c7ec19361 Mon Sep 17 00:00:00 2001 From: Patrick Balsiger Date: Wed, 3 Oct 2018 17:20:48 +0200 Subject: [PATCH] poti plugin to control color wheel --- src/IlluCat.h | 2 ++ src/PotPlugin.h | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 src/PotPlugin.h diff --git a/src/IlluCat.h b/src/IlluCat.h index e34e4f8..a4c4751 100644 --- a/src/IlluCat.h +++ b/src/IlluCat.h @@ -17,6 +17,7 @@ #include #include #include "PixelPlugin.h" +#include "PotPlugin.h" using namespace std; using namespace std::placeholders; @@ -80,6 +81,7 @@ class IlluCat : public MeshSprocket { addPlugin(new WebServerPlugin(webConfig, server)); addPlugin(new WebConfigPlugin(server)); addPlugin(new PixelPlugin(pixelConfig, pixels)); + addPlugin(new PotPlugin()); defaultAnimation(); String softApPrt = "SoftAP IP: " + WiFi.softAPIP().toString(); diff --git a/src/PotPlugin.h b/src/PotPlugin.h new file mode 100644 index 0000000..305015a --- /dev/null +++ b/src/PotPlugin.h @@ -0,0 +1,40 @@ +#ifndef __POT_PLUGIN_H__ +#define __POT_PLUGIN_H__ + +#include +#include "TaskSchedulerDeclarations.h" +#include "ArduinoOTA.h" +#include "Plugin.h" +#include "utils_print.h" +#include "config.h" + +using namespace std; +using namespace std::placeholders; + +class PotPlugin : public Plugin { + public: + Task inputTask; + int currentVal = 0; + PotPlugin(){ + } + void activate(Scheduler* userScheduler, Network* network){ + inputTask.set(TASK_MILLISECOND * 50, TASK_FOREVER, bind(&PotPlugin::checkInput, this)); + userScheduler->addTask(inputTask); + inputTask.enable(); + PRINT_MSG(Serial, SPROCKET_TYPE, "PotPlugin activated"); + } + long toRange(long x, long in_min, long in_max, long out_min, long out_max){ + return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; + } + void checkInput(){ + //Serial.println(String("Pot:") + String(analogRead(A0))); + int newVal = toRange(analogRead(A0), 0, 1024, 0, 255); + if(newVal > 0 && + (newVal >= currentVal + 5 || newVal <= currentVal - 5)){ + publish("pixels/colorWheel",String(newVal)); + currentVal = newVal; + } + } +}; + +#endif \ No newline at end of file