57 lines
1021 B
C++
57 lines
1021 B
C++
#include "Arduino.h"
|
|
#include "detectled.h"
|
|
#include "buttons.h"
|
|
#include "board.h"
|
|
|
|
#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;
|
|
|
|
|
|
void handleDetectLed( void )
|
|
{
|
|
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 )
|
|
{
|
|
for (auto &&i : inputs)
|
|
{
|
|
pinMode(i, INPUT_ANALOG);
|
|
}
|
|
|
|
analogReadResolution(10);
|
|
} |