updated hall code
This commit is contained in:
@@ -1,7 +1,12 @@
|
||||
#include "game.h"
|
||||
|
||||
#include "math.h"
|
||||
|
||||
uint64_t last_hall_read;
|
||||
|
||||
uint32_t last_hall_read;
|
||||
uint16_t last_hall_sample;
|
||||
uint8_t hall_idle_count;
|
||||
bool hall_is_Idle = true;
|
||||
|
||||
void initGame(void)
|
||||
{
|
||||
@@ -14,7 +19,42 @@ void handleGame(void)
|
||||
uint32_t timeNow = millis();
|
||||
if(timeNow - last_hall_read > HALLINTERVAL)
|
||||
{
|
||||
Serial.println(analogRead(HALL_INPUT));
|
||||
uint16_t hall_sample = analogRead(HALL_INPUT);
|
||||
uint16_t hall_delta = (last_hall_sample > hall_sample)? (last_hall_sample - hall_sample) : (hall_sample - last_hall_sample);
|
||||
if(hall_delta > HALLIDLETHRESHOLD)
|
||||
{
|
||||
if(hall_idle_count > HALLIDLESAMPLES)
|
||||
{
|
||||
hall_is_Idle = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
hall_idle_count++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(hall_idle_count == 0)
|
||||
{
|
||||
hall_is_Idle = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
hall_idle_count--;
|
||||
}
|
||||
}
|
||||
Serial.printf("HallSensor: val=%d, delta=%d, count=%d, idle=%s\n",
|
||||
hall_sample,
|
||||
hall_delta,
|
||||
hall_idle_count,
|
||||
(hall_is_Idle? "yes":"no"));
|
||||
last_hall_sample = hall_sample;
|
||||
last_hall_read = timeNow;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
bool hallIsIdle(void)
|
||||
{
|
||||
return hall_is_Idle;
|
||||
}
|
||||
Reference in New Issue
Block a user