Changed to JC_button lib

This commit is contained in:
willem oldemans
2020-11-19 08:27:52 +01:00
parent 8c9176ccbe
commit d184f1785c
8 changed files with 135 additions and 167 deletions

View File

@@ -3,25 +3,55 @@
#include "buttons.h"
#include "board.h"
extern buttons button1;
extern buttons button2;
extern buttons button3;
#define CHANNELS 3
#define SAMPLES 20
unsigned int detectled[CHANNELS] = {0,0,0};
uint32_t detectledRaw[CHANNELS][SAMPLES];
const uint32_t inputs[CHANNELS] = {DETECT1, DETECT2, DETECT3};
const uint32_t leds[CHANNELS] = {LED1, LED2, LED3};
uint32_t sampleIndex = 0;
uint32_t detectled[3] = {0,0,0};
void handleDetectLed( void )
{
detectled[0] = analogRead(DETECT1);
detectled[1] = analogRead(DETECT2);
detectled[2] = analogRead(DETECT3);
for(int i = 0;i < CHANNELS;i++)
{
detectledRaw[i][sampleIndex] = analogRead(inputs[i]);
}
sampleIndex++;
if(sampleIndex == SAMPLES)
{
for(int i = 0;i<CHANNELS;i++)
{
uint64_t sum = 0;
for(int n = 0;n < SAMPLES;n++)
{
sum += detectledRaw[i][n];
}
detectled[i] = sum / SAMPLES;
}
printf("L1 = %u, L2 = %u, L3 = %u",detectled[0],detectled[1],detectled[2]);
sampleIndex = 0;
}
for( auto &&o : leds)
{
digitalWrite(o, 0);
}
}
void initDetectLed( void )
{
pinMode(DETECT1, INPUT_ANALOG);
pinMode(DETECT2, INPUT_ANALOG);
pinMode(DETECT3, INPUT_ANALOG);
analogReadResolution(10);
for (auto &&i : inputs)
{
pinMode(i, INPUT_ANALOG);
}
analogReadResolution(10);
}