mirror of
https://gitlab.com/zwirbel/illucat.git
synced 2025-12-14 17:35:22 +01:00
40 lines
1.3 KiB
C++
40 lines
1.3 KiB
C++
#ifndef __POT_PLUGIN_H__
|
|
#define __POT_PLUGIN_H__
|
|
|
|
#include <FS.h>
|
|
#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 |