changed readAInputs() to non blocking code

This commit is contained in:
ModuloFS 2023-10-29 11:43:12 +01:00
parent 4f7dc4fd0e
commit 897a368c76

View File

@ -334,6 +334,7 @@ const int debounceDelay = 50;
#endif #endif
#ifdef AINPUTS #ifdef AINPUTS
int oldAinput[AInputs]; int oldAinput[AInputs];
unsigned long sumAinput[AInputs];
#endif #endif
#ifdef LPOTIS #ifdef LPOTIS
int Lpoti[LPotis]; int Lpoti[LPotis];
@ -420,6 +421,7 @@ void setup() {
for(int i= 0; i<AInputs;i++){ for(int i= 0; i<AInputs;i++){
pinMode(AInPinmap[i], INPUT); pinMode(AInPinmap[i], INPUT);
oldAinput[i] = -1; oldAinput[i] = -1;
sumAinput[i] = 0;
} }
#endif #endif
#ifdef OUTPUTS #ifdef OUTPUTS
@ -662,6 +664,7 @@ void reconnect(){
#ifdef AINPUTS #ifdef AINPUTS
for (int x = 0; x < AInputs; x++){ for (int x = 0; x < AInputs; x++){
oldAinput[x] = -1; oldAinput[x] = -1;
sumAinput[x] = 0;
} }
#endif #endif
#ifdef LPOTIS #ifdef LPOTIS
@ -809,20 +812,27 @@ void readLPoti(){
#ifdef AINPUTS #ifdef AINPUTS
void readAInputs(){ void readAInputs(){
unsigned long var = 0; static unsigned int samplecount = 0;
for(int i= 0;i<AInputs; i++){ for(int i= 0;i<AInputs; i++){
for(int d= 0;d<smooth; d++){// take couple samples to denoise signal if (samplecount < smooth) {
var = var+ analogRead(AInPinmap[i]); sumAinput[i] = sumAinput[i] + analogRead(AInPinmap[i]);
} }
var = var / smooth; else {
if(oldAinput[i]!= var){ sumAinput[i] = sumAinput[i] / smooth;
oldAinput[i] = var; if(oldAinput[i]!= sumAinput[i]){
oldAinput[i] = sumAinput[i];
sendData('A',AInPinmap[i],oldAinput[i]); sendData('A',AInPinmap[i],oldAinput[i]);
} }
sumAinput[i] = 0;
} }
} }
if(samplecount < smooth){ samplecount = samplecount + 1;}
else {samplecount = 0;}
}
#endif #endif
#ifdef INPUTS #ifdef INPUTS
void readInputs(){ void readInputs(){